From 394862e82948709b9c7be2b8d5d44cb762dd68d3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 29 May 2018 17:12:50 -0700 Subject: [PATCH] Test for asyncIterator existance before defining --- src/harness/unittests/forAwaitOfEvaluation.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/harness/unittests/forAwaitOfEvaluation.ts b/src/harness/unittests/forAwaitOfEvaluation.ts index c46f0481229..339e0ca664b 100644 --- a/src/harness/unittests/forAwaitOfEvaluation.ts +++ b/src/harness/unittests/forAwaitOfEvaluation.ts @@ -18,13 +18,17 @@ namespace ts { throw new Error(`Module '${id}' could not be found.`); } + // Define a custom "Symbol" constructor to attach missing built-in symbols without + // modifying the global "Symbol" constructor // tslint:disable-next-line:variable-name const FakeSymbol: SymbolConstructor = ((description?: string) => Symbol(description)) as any; (FakeSymbol).prototype = Symbol.prototype; for (const key of Object.getOwnPropertyNames(Symbol)) { Object.defineProperty(FakeSymbol, key, Object.getOwnPropertyDescriptor(Symbol, key)!); } - (FakeSymbol).asyncIterator = (FakeSymbol).asyncIterator || Symbol.for("Symbol.asyncIterator"); + + // Add "asyncIterator" if missing + if (!hasProperty(FakeSymbol, "asyncIterator")) Object.defineProperty(FakeSymbol, "asyncIterator", { value: Symbol.for("Symbol.asyncIterator"), configurable: true }); function evaluate(result: compiler.CompilationResult) { const output = result.getOutput(sourceFile, "js")!;