diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 27d0617c5affa..3965665ba19e1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12623,7 +12623,7 @@ namespace ts { * callable `then` signature. */ function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type { - if (languageVersion >= ScriptTarget.ES6) { + if (compilerOptions.noCustomAsyncPromise && languageVersion >= ScriptTarget.ES6) { const returnType = getTypeFromTypeNode(node.type); return checkCorrectPromiseType(returnType, node.type); } @@ -13029,6 +13029,10 @@ namespace ts { } function checkCollisionWithGlobalPromiseInGeneratedCode(node: Node, name: Identifier): void { + if (!compilerOptions.noCustomAsyncPromise) { + return; + } + if (!needCollisionCheckForIdentifier(node, name, "Promise")) { return; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 5bbd74d6f47f4..0a4481483c577 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -299,6 +299,11 @@ namespace ts { name: "noImplicitUseStrict", type: "boolean", description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output + }, + { + name: "noCustomAsyncPromise", + type: "boolean", + experimental: true } ]; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 72614756fb79c..212d9f05510d9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -296,11 +296,11 @@ namespace ts { * If loop contains block scoped binding captured in some function then loop body is converted to a function. * Lexical bindings declared in loop initializer will be passed into the loop body function as parameters, * however if this binding is modified inside the body - this new value should be propagated back to the original binding. - * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body. + * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body. * On every iteration this variable is initialized with value of corresponding binding. * At every point where control flow leaves the loop either explicitly (break/continue) or implicitly (at the end of loop body) * we copy the value inside the loop to the out parameter holder. - * + * * for (let x;;) { * let a = 1; * let b = () => a; @@ -308,9 +308,9 @@ namespace ts { * if (...) break; * ... * } - * + * * will be converted to - * + * * var out_x; * var loop = function(x) { * var a = 1; @@ -326,7 +326,7 @@ namespace ts { * x = out_x; * if (state === "break") break; * } - * + * * NOTE: values to out parameters are not copies if loop is abrupted with 'return' - in this case this will end the entire enclosing function * so nobody can observe this new value. */ @@ -3049,7 +3049,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } writeLine(); - // end of loop body -> copy out parameter + // end of loop body -> copy out parameter copyLoopOutParameters(convertedLoopState, CopyDirection.ToOutParameter, /*emitAsStatements*/true); decreaseIndent(); @@ -4685,7 +4685,7 @@ const _super = (function (geti, seti) { write(", void 0, "); } - if (languageVersion >= ScriptTarget.ES6 || !promiseConstructor) { + if (!promiseConstructor || (compilerOptions.noCustomAsyncPromise && languageVersion >= ScriptTarget.ES6)) { write("void 0"); } else { @@ -7245,7 +7245,7 @@ const _super = (function (geti, seti) { } // text should be quoted string - // for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same + // for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same const key = text.substr(1, text.length - 2); if (hasProperty(groupIndices, key)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 31ff055f986a2..d57ec88892bb7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2442,6 +2442,8 @@ namespace ts { /* @internal */ skipDefaultLibCheck?: boolean; // Do not perform validation of output file name in transpile scenarios /* @internal */ suppressOutputPathCheck?: boolean; + // Disallow custom promise return types in async functions. + /* @internal */ noCustomAsyncPromise?: boolean; [option: string]: string | number | boolean; } diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt b/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt new file mode 100644 index 0000000000000..ec532d1380d20 --- /dev/null +++ b/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts(3,16): error TS1055: Type 'PromiseAlias' is not a valid async function return type. + + +==== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts (1 errors) ==== + type PromiseAlias = Promise; + + async function f(): PromiseAlias { + ~ +!!! error TS1055: Type 'PromiseAlias' is not a valid async function return type. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.js b/tests/baselines/reference/asyncAliasReturnType_es6.js index 45fe3228f6ebd..0af63b0bfa604 100644 --- a/tests/baselines/reference/asyncAliasReturnType_es6.js +++ b/tests/baselines/reference/asyncAliasReturnType_es6.js @@ -6,6 +6,6 @@ async function f(): PromiseAlias { //// [asyncAliasReturnType_es6.js] function f() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, PromiseAlias, function* () { }); } diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.symbols b/tests/baselines/reference/asyncAliasReturnType_es6.symbols deleted file mode 100644 index 4d6db6a1ef4c4..0000000000000 --- a/tests/baselines/reference/asyncAliasReturnType_es6.symbols +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts === -type PromiseAlias = Promise; ->PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0)) ->T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18)) ->Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18)) - -async function f(): PromiseAlias { ->f : Symbol(f, Decl(asyncAliasReturnType_es6.ts, 0, 34)) ->PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0)) -} diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.types b/tests/baselines/reference/asyncAliasReturnType_es6.types deleted file mode 100644 index 8426d2a3542f4..0000000000000 --- a/tests/baselines/reference/asyncAliasReturnType_es6.types +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts === -type PromiseAlias = Promise; ->PromiseAlias : Promise ->T : T ->Promise : Promise ->T : T - -async function f(): PromiseAlias { ->f : () => Promise ->PromiseAlias : Promise -} diff --git a/tests/baselines/reference/asyncArrowFunction1_es6.js b/tests/baselines/reference/asyncArrowFunction1_es6.js index 0026cd91a7ef9..4f03acc5ced43 100644 --- a/tests/baselines/reference/asyncArrowFunction1_es6.js +++ b/tests/baselines/reference/asyncArrowFunction1_es6.js @@ -4,5 +4,5 @@ var foo = async (): Promise => { }; //// [asyncArrowFunction1_es6.js] -var foo = () => __awaiter(this, void 0, void 0, function* () { +var foo = () => __awaiter(this, void 0, Promise, function* () { }); diff --git a/tests/baselines/reference/asyncArrowFunction6_es6.js b/tests/baselines/reference/asyncArrowFunction6_es6.js index a01e53f5b114f..54b8aa1f6b154 100644 --- a/tests/baselines/reference/asyncArrowFunction6_es6.js +++ b/tests/baselines/reference/asyncArrowFunction6_es6.js @@ -4,5 +4,5 @@ var foo = async (a = await): Promise => { } //// [asyncArrowFunction6_es6.js] -var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { +var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () { }); diff --git a/tests/baselines/reference/asyncArrowFunction7_es6.js b/tests/baselines/reference/asyncArrowFunction7_es6.js index fab705c0b76e2..ac68a8fd2f865 100644 --- a/tests/baselines/reference/asyncArrowFunction7_es6.js +++ b/tests/baselines/reference/asyncArrowFunction7_es6.js @@ -7,8 +7,8 @@ var bar = async (): Promise => { } //// [asyncArrowFunction7_es6.js] -var bar = () => __awaiter(this, void 0, void 0, function* () { +var bar = () => __awaiter(this, void 0, Promise, function* () { // 'await' here is an identifier, and not an await expression. - var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { + var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () { }); }); diff --git a/tests/baselines/reference/asyncArrowFunction8_es6.js b/tests/baselines/reference/asyncArrowFunction8_es6.js index 0c33cfcfa2de0..9cee5ee1525d7 100644 --- a/tests/baselines/reference/asyncArrowFunction8_es6.js +++ b/tests/baselines/reference/asyncArrowFunction8_es6.js @@ -5,6 +5,6 @@ var foo = async (): Promise => { } //// [asyncArrowFunction8_es6.js] -var foo = () => __awaiter(this, void 0, void 0, function* () { +var foo = () => __awaiter(this, void 0, Promise, function* () { var v = { [yield ]: foo }; }); diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js index 4022fde7f54e8..2feb26d6fafd5 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js @@ -52,36 +52,36 @@ function f0() { return __awaiter(this, void 0, void 0, function* () { }); } function f1() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); } function f3() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } let f4 = function () { return __awaiter(this, void 0, void 0, function* () { }); }; let f5 = function () { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); }; let f6 = function () { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); }; let f7 = () => __awaiter(this, void 0, void 0, function* () { }); -let f8 = () => __awaiter(this, void 0, void 0, function* () { }); -let f9 = () => __awaiter(this, void 0, void 0, function* () { }); +let f8 = () => __awaiter(this, void 0, Promise, function* () { }); +let f9 = () => __awaiter(this, void 0, MyPromise, function* () { }); let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; }); let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); -let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); -let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; }); +let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); +let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; }); let o = { m1() { return __awaiter(this, void 0, void 0, function* () { }); }, m2() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); }, m3() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } }; class C { @@ -89,19 +89,19 @@ class C { return __awaiter(this, void 0, void 0, function* () { }); } m2() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); } m3() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } static m4() { return __awaiter(this, void 0, void 0, function* () { }); } static m5() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); } static m6() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } } var M; diff --git a/tests/baselines/reference/asyncAwait_es6.js b/tests/baselines/reference/asyncAwait_es6.js index be2eb90e3e4fb..f15a8e2df7c0a 100644 --- a/tests/baselines/reference/asyncAwait_es6.js +++ b/tests/baselines/reference/asyncAwait_es6.js @@ -52,36 +52,36 @@ function f0() { return __awaiter(this, void 0, void 0, function* () { }); } function f1() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); } function f3() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } let f4 = function () { return __awaiter(this, void 0, void 0, function* () { }); }; let f5 = function () { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); }; let f6 = function () { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); }; let f7 = () => __awaiter(this, void 0, void 0, function* () { }); -let f8 = () => __awaiter(this, void 0, void 0, function* () { }); -let f9 = () => __awaiter(this, void 0, void 0, function* () { }); +let f8 = () => __awaiter(this, void 0, Promise, function* () { }); +let f9 = () => __awaiter(this, void 0, MyPromise, function* () { }); let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; }); let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); -let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); -let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; }); +let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); +let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; }); let o = { m1() { return __awaiter(this, void 0, void 0, function* () { }); }, m2() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); }, m3() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } }; class C { @@ -89,19 +89,19 @@ class C { return __awaiter(this, void 0, void 0, function* () { }); } m2() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); } m3() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } static m4() { return __awaiter(this, void 0, void 0, function* () { }); } static m5() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Promise, function* () { }); } static m6() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, MyPromise, function* () { }); } } var M; diff --git a/tests/baselines/reference/asyncFunctionDeclaration11_es6.js b/tests/baselines/reference/asyncFunctionDeclaration11_es6.js index 6fe8921434c84..a44343cef7822 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration11_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration11_es6.js @@ -4,6 +4,6 @@ async function await(): Promise { //// [asyncFunctionDeclaration11_es6.js] function await() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration13_es6.js b/tests/baselines/reference/asyncFunctionDeclaration13_es6.js index 6fab6c39947d3..4257c8691c25b 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration13_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration13_es6.js @@ -7,7 +7,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration13_es6.js] function foo() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { // Legal to use 'await' in a type context. var v; }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration14_es6.js b/tests/baselines/reference/asyncFunctionDeclaration14_es6.js index f584f9178426f..f32d106f92e37 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration14_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration14_es6.js @@ -5,7 +5,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration14_es6.js] function foo() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { return; }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index e8d3e7d79b1e8..29158d9053bf8 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -1,33 +1,44 @@ -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,16): error TS1055: Type '{}' is not a valid async function return type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,16): error TS1055: Type 'any' is not a valid async function return type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,16): error TS1055: Type 'number' is not a valid async function return type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,16): error TS1055: Type 'PromiseLike' is not a valid async function return type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type. + Type 'Thenable' is not assignable to type 'PromiseLike'. + Types of property 'then' are incompatible. + Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. + Type 'void' is not assignable to type 'PromiseLike'. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. -==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (7 errors) ==== +==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (8 errors) ==== declare class Thenable { then(): void; } declare let a: any; declare let obj: { then: string; }; declare let thenable: Thenable; async function fn1() { } // valid: Promise async function fn2(): { } { } // error - ~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. + ~~~ +!!! error TS1055: Type '{}' is not a valid async function return type. async function fn3(): any { } // error - ~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. + ~~~ +!!! error TS1055: Type 'any' is not a valid async function return type. async function fn4(): number { } // error - ~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. + ~~~ +!!! error TS1055: Type 'number' is not a valid async function return type. async function fn5(): PromiseLike { } // error - ~~~~~~~~~~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. + ~~~ +!!! error TS1055: Type 'PromiseLike' is not a valid async function return type. async function fn6(): Thenable { } // error - ~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. + ~~~ +!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. + ~~~ +!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. +!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. +!!! error TS1055: Types of property 'then' are incompatible. +!!! error TS1055: Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. +!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike'. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.js b/tests/baselines/reference/asyncFunctionDeclaration15_es6.js index 174a95d6f669f..0efbd6f66f98a 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.js @@ -38,10 +38,10 @@ function fn4() { return __awaiter(this, void 0, void 0, function* () { }); } // error function fn5() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, PromiseLike, function* () { }); } // error function fn6() { - return __awaiter(this, void 0, void 0, function* () { }); + return __awaiter(this, void 0, Thenable, function* () { }); } // error function fn7() { return __awaiter(this, void 0, void 0, function* () { return; }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration1_es6.js b/tests/baselines/reference/asyncFunctionDeclaration1_es6.js index e92d55dc0e2ce..263e27fa35efa 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration1_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration1_es6.js @@ -4,6 +4,6 @@ async function foo(): Promise { //// [asyncFunctionDeclaration1_es6.js] function foo() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js index a70316989b380..8c37968ab4c22 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js @@ -4,6 +4,6 @@ async function foo(a = await): Promise { //// [asyncFunctionDeclaration6_es6.js] function foo(a = yield ) { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js index 0d360fa866ccb..ef66df4e4133a 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js @@ -7,10 +7,10 @@ async function bar(): Promise { //// [asyncFunctionDeclaration7_es6.js] function bar() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { // 'await' here is an identifier, and not a yield expression. function foo(a = yield ) { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { }); } }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration9_es6.js b/tests/baselines/reference/asyncFunctionDeclaration9_es6.js index c57c0eb395a72..9723a69f2a23b 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration9_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration9_es6.js @@ -5,7 +5,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration9_es6.js] function foo() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { var v = { [yield ]: foo }; }); } diff --git a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt deleted file mode 100644 index 43b454826447c..0000000000000 --- a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise type. - - -==== tests/cases/conformance/async/es6/task.ts (0 errors) ==== - export class Task extends Promise { } - -==== tests/cases/conformance/async/es6/test.ts (1 errors) ==== - import { Task } from "./task"; - class Test { - async example(): Task { return; } - ~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. - } \ No newline at end of file diff --git a/tests/baselines/reference/asyncImportedPromise_es6.js b/tests/baselines/reference/asyncImportedPromise_es6.js index 56a41b0283f5b..8cad65e6d5b0b 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.js +++ b/tests/baselines/reference/asyncImportedPromise_es6.js @@ -24,8 +24,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments)).next()); }); }; +const task_1 = require("./task"); class Test { example() { - return __awaiter(this, void 0, void 0, function* () { return; }); + return __awaiter(this, void 0, task_1.Task, function* () { return; }); } } diff --git a/tests/baselines/reference/asyncImportedPromise_es6.symbols b/tests/baselines/reference/asyncImportedPromise_es6.symbols new file mode 100644 index 0000000000000..45cf47d2b45b2 --- /dev/null +++ b/tests/baselines/reference/asyncImportedPromise_es6.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/async/es6/task.ts === +export class Task extends Promise { } +>Task : Symbol(Task, Decl(task.ts, 0, 0)) +>T : Symbol(T, Decl(task.ts, 0, 18)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(task.ts, 0, 18)) + +=== tests/cases/conformance/async/es6/test.ts === +import { Task } from "./task"; +>Task : Symbol(Task, Decl(test.ts, 0, 8)) + +class Test { +>Test : Symbol(Test, Decl(test.ts, 0, 30)) + + async example(): Task { return; } +>example : Symbol(example, Decl(test.ts, 1, 12)) +>T : Symbol(T, Decl(test.ts, 2, 18)) +>Task : Symbol(Task, Decl(test.ts, 0, 8)) +>T : Symbol(T, Decl(test.ts, 2, 18)) +} diff --git a/tests/baselines/reference/asyncImportedPromise_es6.types b/tests/baselines/reference/asyncImportedPromise_es6.types new file mode 100644 index 0000000000000..424f14b34d37f --- /dev/null +++ b/tests/baselines/reference/asyncImportedPromise_es6.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/async/es6/task.ts === +export class Task extends Promise { } +>Task : Task +>T : T +>Promise : Promise +>T : T + +=== tests/cases/conformance/async/es6/test.ts === +import { Task } from "./task"; +>Task : typeof Task + +class Test { +>Test : Test + + async example(): Task { return; } +>example : () => Task +>T : T +>Task : Task +>T : T +} diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt deleted file mode 100644 index 205ea01673631..0000000000000 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise type. - - -==== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts (1 errors) ==== - namespace X { - export class MyPromise extends Promise { - } - } - - async function f(): X.MyPromise { - ~~~~~~~~~~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise type. - } \ No newline at end of file diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.js b/tests/baselines/reference/asyncQualifiedReturnType_es6.js index 4d5aa87bbffb4..1da37946254f6 100644 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.js +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.js @@ -15,6 +15,6 @@ var X; X.MyPromise = MyPromise; })(X || (X = {})); function f() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, X.MyPromise, function* () { }); } diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols b/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols new file mode 100644 index 0000000000000..5d27d04ea3bdc --- /dev/null +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts === +namespace X { +>X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0)) + + export class MyPromise extends Promise { +>MyPromise : Symbol(MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13)) +>T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27)) + } +} + +async function f(): X.MyPromise { +>f : Symbol(f, Decl(asyncQualifiedReturnType_es6.ts, 3, 1)) +>X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0)) +>MyPromise : Symbol(X.MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13)) +} diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.types b/tests/baselines/reference/asyncQualifiedReturnType_es6.types new file mode 100644 index 0000000000000..3b438eb93b68a --- /dev/null +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts === +namespace X { +>X : typeof X + + export class MyPromise extends Promise { +>MyPromise : MyPromise +>T : T +>Promise : Promise +>T : T + } +} + +async function f(): X.MyPromise { +>f : () => X.MyPromise +>X : any +>MyPromise : X.MyPromise +} diff --git a/tests/baselines/reference/awaitBinaryExpression1_es6.js b/tests/baselines/reference/awaitBinaryExpression1_es6.js index a19e94353d595..8deb771f5abf2 100644 --- a/tests/baselines/reference/awaitBinaryExpression1_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression1_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression1_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = (yield p) || a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression2_es6.js b/tests/baselines/reference/awaitBinaryExpression2_es6.js index 7fb1a70446b26..506af50a0efba 100644 --- a/tests/baselines/reference/awaitBinaryExpression2_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression2_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression2_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = (yield p) && a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression3_es6.js b/tests/baselines/reference/awaitBinaryExpression3_es6.js index f845ce1242148..4b298d7b94751 100644 --- a/tests/baselines/reference/awaitBinaryExpression3_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression3_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression3_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = (yield p) + a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression4_es6.js b/tests/baselines/reference/awaitBinaryExpression4_es6.js index b6e14c8248761..4d31358898442 100644 --- a/tests/baselines/reference/awaitBinaryExpression4_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression4_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression4_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = yield p, a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression5_es6.js b/tests/baselines/reference/awaitBinaryExpression5_es6.js index 65a5bbfee777f..01d6c50f6f03e 100644 --- a/tests/baselines/reference/awaitBinaryExpression5_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression5_es6.js @@ -10,7 +10,7 @@ async function func(): Promise { //// [awaitBinaryExpression5_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var o; o.a = yield p; diff --git a/tests/baselines/reference/awaitCallExpression1_es6.js b/tests/baselines/reference/awaitCallExpression1_es6.js index aeeb598e3bf18..f9dad87a8b6b3 100644 --- a/tests/baselines/reference/awaitCallExpression1_es6.js +++ b/tests/baselines/reference/awaitCallExpression1_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression1_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression2_es6.js b/tests/baselines/reference/awaitCallExpression2_es6.js index b41735275a842..87d99cd079399 100644 --- a/tests/baselines/reference/awaitCallExpression2_es6.js +++ b/tests/baselines/reference/awaitCallExpression2_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression2_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = fn(yield p, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression3_es6.js b/tests/baselines/reference/awaitCallExpression3_es6.js index 74dee3e7e427c..f397d83c3a14e 100644 --- a/tests/baselines/reference/awaitCallExpression3_es6.js +++ b/tests/baselines/reference/awaitCallExpression3_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression3_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = fn(a, yield p, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression4_es6.js b/tests/baselines/reference/awaitCallExpression4_es6.js index 682a1776ac53c..d8824d7e7a007 100644 --- a/tests/baselines/reference/awaitCallExpression4_es6.js +++ b/tests/baselines/reference/awaitCallExpression4_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression4_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = (yield pfn)(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression5_es6.js b/tests/baselines/reference/awaitCallExpression5_es6.js index 30889b350115f..f39a633765d88 100644 --- a/tests/baselines/reference/awaitCallExpression5_es6.js +++ b/tests/baselines/reference/awaitCallExpression5_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression5_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = o.fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression6_es6.js b/tests/baselines/reference/awaitCallExpression6_es6.js index 55d86119d6495..de8477fa9388a 100644 --- a/tests/baselines/reference/awaitCallExpression6_es6.js +++ b/tests/baselines/reference/awaitCallExpression6_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression6_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = o.fn(yield p, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression7_es6.js b/tests/baselines/reference/awaitCallExpression7_es6.js index df805266ff3a2..24edc3b9393e6 100644 --- a/tests/baselines/reference/awaitCallExpression7_es6.js +++ b/tests/baselines/reference/awaitCallExpression7_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression7_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = o.fn(a, yield p, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression8_es6.js b/tests/baselines/reference/awaitCallExpression8_es6.js index 8d7bb4b83ce96..8bee6112a7a39 100644 --- a/tests/baselines/reference/awaitCallExpression8_es6.js +++ b/tests/baselines/reference/awaitCallExpression8_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression8_es6.js] function func() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { "before"; var b = (yield po).fn(a, a, a); "after"; diff --git a/tests/baselines/reference/noCustomAsyncReturnType_es6.errors.txt b/tests/baselines/reference/noCustomAsyncReturnType_es6.errors.txt new file mode 100644 index 0000000000000..e3f70fb40cde4 --- /dev/null +++ b/tests/baselines/reference/noCustomAsyncReturnType_es6.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts(3,5): error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions. +tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts(5,28): error TS1064: The return type of an async function or method must be the global Promise type. + + +==== tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts (2 errors) ==== + + interface Promise extends PromiseLike {} + var Promise: PromiseConstructorLike; + ~~~~~~~ +!!! error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions. + + export async function f(): Promise { + ~~~~~~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. + } + \ No newline at end of file diff --git a/tests/baselines/reference/noCustomAsyncReturnType_es6.js b/tests/baselines/reference/noCustomAsyncReturnType_es6.js new file mode 100644 index 0000000000000..05eb4afff39b0 --- /dev/null +++ b/tests/baselines/reference/noCustomAsyncReturnType_es6.js @@ -0,0 +1,23 @@ +//// [noCustomAsyncReturnType_es6.ts] + +interface Promise extends PromiseLike {} +var Promise: PromiseConstructorLike; + +export async function f(): Promise { +} + + +//// [noCustomAsyncReturnType_es6.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +var Promise; +export function f() { + return __awaiter(this, void 0, void 0, function* () { + }); +} diff --git a/tests/baselines/reference/reachabilityChecks7.js b/tests/baselines/reference/reachabilityChecks7.js index 0a6b5b0dac7b5..0f14eb697669f 100644 --- a/tests/baselines/reference/reachabilityChecks7.js +++ b/tests/baselines/reference/reachabilityChecks7.js @@ -50,7 +50,7 @@ let x = function () { }; // async function with which promised type is void - return can be omitted function f2() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { }); } function f3(x) { @@ -60,7 +60,7 @@ function f3(x) { }); } function f4() { - return __awaiter(this, void 0, void 0, function* () { + return __awaiter(this, void 0, Promise, function* () { }); } function voidFunc() { diff --git a/tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts b/tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts new file mode 100644 index 0000000000000..774cf6efab739 --- /dev/null +++ b/tests/cases/conformance/async/es6/noCustomAsyncReturnType_es6.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @noCustomAsyncPromise: true + +interface Promise extends PromiseLike {} +var Promise: PromiseConstructorLike; + +export async function f(): Promise { +}