diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56ec54781e7..b839d862430 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8162,10 +8162,13 @@ namespace ts { // can explicitly bound arguments objects if (symbol === argumentsSymbol) { const container = getContainingFunction(node); - if (container.kind === SyntaxKind.ArrowFunction) { - if (languageVersion < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { + if (container.kind === SyntaxKind.ArrowFunction) { error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } + else if (hasModifier(container, ModifierFlags.Async)) { + error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES3_and_ES5_Consider_using_a_standard_function_or_method); + } } if (node.flags & NodeFlags.AwaitContext) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 75b5827ab48..b2c67271001 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1695,7 +1695,7 @@ "category": "Error", "code": 2521 }, - "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression.": { + "The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method.": { "category": "Error", "code": 2522 }, diff --git a/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.js b/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.js new file mode 100644 index 00000000000..df308028361 --- /dev/null +++ b/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.js @@ -0,0 +1,6 @@ +//// [arrowFunctionWithParameterNameAsync_es5.ts] + +const x = async => async; + +//// [arrowFunctionWithParameterNameAsync_es5.js] +var x = function (async) { return async; }; diff --git a/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.symbols b/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.symbols new file mode 100644 index 00000000000..43c9c343efe --- /dev/null +++ b/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts === + +const x = async => async; +>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 5)) +>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 9)) +>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 9)) + diff --git a/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.types b/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.types new file mode 100644 index 00000000000..bd567320f1d --- /dev/null +++ b/tests/baselines/reference/arrowFunctionWithParameterNameAsync_es5.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts === + +const x = async => async; +>x : (async: any) => any +>async => async : (async: any) => any +>async : any +>async : any + diff --git a/tests/baselines/reference/asyncArrowFunction10_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction10_es5.errors.txt new file mode 100644 index 00000000000..0b3596282ff --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction10_es5.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts(4,11): error TS2304: Cannot find name 'await'. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts (1 errors) ==== + + var foo = async (): Promise => { + // Legal to use 'await' in a type context. + var v: await; + ~~~~~ +!!! error TS2304: Cannot find name 'await'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction10_es5.js b/tests/baselines/reference/asyncArrowFunction10_es5.js new file mode 100644 index 00000000000..2fc2ac56f9f --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction10_es5.js @@ -0,0 +1,16 @@ +//// [asyncArrowFunction10_es5.ts] + +var foo = async (): Promise => { + // Legal to use 'await' in a type context. + var v: await; +} + + +//// [asyncArrowFunction10_es5.js] +var _this = this; +var foo = function () { return __awaiter(_this, void 0, void 0, function () { + var v; + return __generator(this, function (_a) { + return [2 /*return*/]; + }); +}); }; diff --git a/tests/baselines/reference/asyncArrowFunction1_es5.js b/tests/baselines/reference/asyncArrowFunction1_es5.js new file mode 100644 index 00000000000..aac185c63a1 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction1_es5.js @@ -0,0 +1,12 @@ +//// [asyncArrowFunction1_es5.ts] + +var foo = async (): Promise => { +}; + +//// [asyncArrowFunction1_es5.js] +var _this = this; +var foo = function () { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/]; + }); +}); }; diff --git a/tests/baselines/reference/asyncArrowFunction1_es5.symbols b/tests/baselines/reference/asyncArrowFunction1_es5.symbols new file mode 100644 index 00000000000..c37985dc347 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction1_es5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts === + +var foo = async (): Promise => { +>foo : Symbol(foo, Decl(asyncArrowFunction1_es5.ts, 1, 3)) +>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +}; diff --git a/tests/baselines/reference/asyncArrowFunction1_es5.types b/tests/baselines/reference/asyncArrowFunction1_es5.types new file mode 100644 index 00000000000..bde82d2b836 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction1_es5.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts === + +var foo = async (): Promise => { +>foo : () => Promise +>async (): Promise => {} : () => Promise +>Promise : Promise + +}; diff --git a/tests/baselines/reference/asyncArrowFunction2_es5.js b/tests/baselines/reference/asyncArrowFunction2_es5.js new file mode 100644 index 00000000000..d77837a5433 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction2_es5.js @@ -0,0 +1,7 @@ +//// [asyncArrowFunction2_es5.ts] +var f = (await) => { +} + +//// [asyncArrowFunction2_es5.js] +var f = function (await) { +}; diff --git a/tests/baselines/reference/asyncArrowFunction2_es5.symbols b/tests/baselines/reference/asyncArrowFunction2_es5.symbols new file mode 100644 index 00000000000..b195e9c2695 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction2_es5.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts === +var f = (await) => { +>f : Symbol(f, Decl(asyncArrowFunction2_es5.ts, 0, 3)) +>await : Symbol(await, Decl(asyncArrowFunction2_es5.ts, 0, 9)) +} diff --git a/tests/baselines/reference/asyncArrowFunction2_es5.types b/tests/baselines/reference/asyncArrowFunction2_es5.types new file mode 100644 index 00000000000..e51a17abd35 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction2_es5.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts === +var f = (await) => { +>f : (await: any) => void +>(await) => {} : (await: any) => void +>await : any +} diff --git a/tests/baselines/reference/asyncArrowFunction3_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction3_es5.errors.txt new file mode 100644 index 00000000000..01c74ab3620 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction3_es5.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts(1,20): error TS2372: Parameter 'await' cannot be referenced in its initializer. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts (1 errors) ==== + function f(await = await) { + ~~~~~ +!!! error TS2372: Parameter 'await' cannot be referenced in its initializer. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction3_es5.js b/tests/baselines/reference/asyncArrowFunction3_es5.js new file mode 100644 index 00000000000..3c73e6f9f58 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction3_es5.js @@ -0,0 +1,8 @@ +//// [asyncArrowFunction3_es5.ts] +function f(await = await) { +} + +//// [asyncArrowFunction3_es5.js] +function f(await) { + if (await === void 0) { await = await; } +} diff --git a/tests/baselines/reference/asyncArrowFunction4_es5.js b/tests/baselines/reference/asyncArrowFunction4_es5.js new file mode 100644 index 00000000000..cbaae99a9c6 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction4_es5.js @@ -0,0 +1,7 @@ +//// [asyncArrowFunction4_es5.ts] +var await = () => { +} + +//// [asyncArrowFunction4_es5.js] +var await = function () { +}; diff --git a/tests/baselines/reference/asyncArrowFunction4_es5.symbols b/tests/baselines/reference/asyncArrowFunction4_es5.symbols new file mode 100644 index 00000000000..affb1f188a8 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction4_es5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts === +var await = () => { +>await : Symbol(await, Decl(asyncArrowFunction4_es5.ts, 0, 3)) +} diff --git a/tests/baselines/reference/asyncArrowFunction4_es5.types b/tests/baselines/reference/asyncArrowFunction4_es5.types new file mode 100644 index 00000000000..3b452365095 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction4_es5.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts === +var await = () => { +>await : () => void +>() => {} : () => void +} diff --git a/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt new file mode 100644 index 00000000000..e19113e66f8 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,11): error TS2304: Cannot find name 'async'. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,18): error TS2304: Cannot find name 'await'. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,24): error TS1005: ',' expected. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,26): error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,33): error TS1005: '=' expected. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,40): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts (6 errors) ==== + + var foo = async (await): Promise => { + ~~~~~ +!!! error TS2304: Cannot find name 'async'. + ~~~~~ +!!! error TS2304: Cannot find name 'await'. + ~ +!!! error TS1005: ',' expected. + ~~~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'. + ~ +!!! error TS1005: '=' expected. + ~~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction5_es5.js b/tests/baselines/reference/asyncArrowFunction5_es5.js new file mode 100644 index 00000000000..ff5ee68d4c7 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction5_es5.js @@ -0,0 +1,9 @@ +//// [asyncArrowFunction5_es5.ts] + +var foo = async (await): Promise => { +} + +//// [asyncArrowFunction5_es5.js] +var foo = async(await), Promise = ; +{ +} diff --git a/tests/baselines/reference/asyncArrowFunction6_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction6_es5.errors.txt new file mode 100644 index 00000000000..a957589bd94 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction6_es5.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts(2,22): error TS2524: 'await' expressions cannot be used in a parameter initializer. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts(2,27): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts (2 errors) ==== + + var foo = async (a = await): Promise => { + ~~~~~ +!!! error TS2524: 'await' expressions cannot be used in a parameter initializer. + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction6_es5.js b/tests/baselines/reference/asyncArrowFunction6_es5.js new file mode 100644 index 00000000000..ea61a1b44b5 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction6_es5.js @@ -0,0 +1,15 @@ +//// [asyncArrowFunction6_es5.ts] + +var foo = async (a = await): Promise => { +} + +//// [asyncArrowFunction6_es5.js] +var _this = this; +var foo = function (a) { + if (a === void 0) { a = yield ; } + return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/]; + }); + }); +}; diff --git a/tests/baselines/reference/asyncArrowFunction7_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction7_es5.errors.txt new file mode 100644 index 00000000000..cc5cf2bb61d --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction7_es5.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts(4,24): error TS2524: 'await' expressions cannot be used in a parameter initializer. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts(4,29): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts (2 errors) ==== + + var bar = async (): Promise => { + // 'await' here is an identifier, and not an await expression. + var foo = async (a = await): Promise => { + ~~~~~ +!!! error TS2524: 'await' expressions cannot be used in a parameter initializer. + ~ +!!! error TS1109: Expression expected. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction7_es5.js b/tests/baselines/reference/asyncArrowFunction7_es5.js new file mode 100644 index 00000000000..19e589fa542 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction7_es5.js @@ -0,0 +1,25 @@ +//// [asyncArrowFunction7_es5.ts] + +var bar = async (): Promise => { + // 'await' here is an identifier, and not an await expression. + var foo = async (a = await): Promise => { + } +} + +//// [asyncArrowFunction7_es5.js] +var _this = this; +var bar = function () { return __awaiter(_this, void 0, void 0, function () { + _this = this; + var foo; + return __generator(this, function (_a) { + foo = function (a) { + if (a === void 0) { a = yield ; } + return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/]; + }); + }); + }; + return [2 /*return*/]; + }); +}); var _this; }; diff --git a/tests/baselines/reference/asyncArrowFunction8_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction8_es5.errors.txt new file mode 100644 index 00000000000..e2e69fc5bee --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction8_es5.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts(3,19): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts (1 errors) ==== + + var foo = async (): Promise => { + var v = { [await]: foo } + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction8_es5.js b/tests/baselines/reference/asyncArrowFunction8_es5.js new file mode 100644 index 00000000000..30432949262 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction8_es5.js @@ -0,0 +1,21 @@ +//// [asyncArrowFunction8_es5.ts] + +var foo = async (): Promise => { + var v = { [await]: foo } +} + +//// [asyncArrowFunction8_es5.js] +var _this = this; +var foo = function () { return __awaiter(_this, void 0, void 0, function () { + var v, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = {}; + return [4 /*yield*/, ]; + case 1: + v = (_a[_b.sent()] = foo, _a); + return [2 /*return*/]; + } + }); +}); }; diff --git a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt new file mode 100644 index 00000000000..30846e06d6a --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,11): error TS2304: Cannot find name 'async'. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,18): error TS2304: Cannot find name 'a'. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,37): error TS1005: ',' expected. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,39): error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,46): error TS1005: '=' expected. +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,53): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts (6 errors) ==== + var foo = async (a = await => await): Promise => { + ~~~~~ +!!! error TS2304: Cannot find name 'async'. + ~ +!!! error TS2304: Cannot find name 'a'. + ~ +!!! error TS1005: ',' expected. + ~~~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'. + ~ +!!! error TS1005: '=' expected. + ~~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunction9_es5.js b/tests/baselines/reference/asyncArrowFunction9_es5.js new file mode 100644 index 00000000000..2506024f326 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunction9_es5.js @@ -0,0 +1,8 @@ +//// [asyncArrowFunction9_es5.ts] +var foo = async (a = await => await): Promise => { +} + +//// [asyncArrowFunction9_es5.js] +var foo = async(a = function (await) { return await; }), Promise = ; +{ +} diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.errors.txt b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.errors.txt new file mode 100644 index 00000000000..e0a1ef45e8c --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts(4,52): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression. + + +==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts (1 errors) ==== + class C { + method() { + function other() {} + var fn = async () => await other.apply(this, arguments); + ~~~~~~~~~ +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js new file mode 100644 index 00000000000..e73ef6ddd4d --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js @@ -0,0 +1,25 @@ +//// [asyncArrowFunctionCapturesArguments_es5.ts] +class C { + method() { + function other() {} + var fn = async () => await other.apply(this, arguments); + } +} + + +//// [asyncArrowFunctionCapturesArguments_es5.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + var _this = this; + function other() { } + var fn = function () { return __awaiter(_this, arguments, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, other.apply(this, arguments)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); }; + }; + return C; +}()); diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.js b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.js new file mode 100644 index 00000000000..5c9727bddab --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.js @@ -0,0 +1,23 @@ +//// [asyncArrowFunctionCapturesThis_es5.ts] +class C { + method() { + var fn = async () => await this; + } +} + + +//// [asyncArrowFunctionCapturesThis_es5.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + var _this = this; + var fn = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); }; + }; + return C; +}()); diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.symbols b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.symbols new file mode 100644 index 00000000000..c0415839891 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts === +class C { +>C : Symbol(C, Decl(asyncArrowFunctionCapturesThis_es5.ts, 0, 0)) + + method() { +>method : Symbol(C.method, Decl(asyncArrowFunctionCapturesThis_es5.ts, 0, 9)) + + var fn = async () => await this; +>fn : Symbol(fn, Decl(asyncArrowFunctionCapturesThis_es5.ts, 2, 9)) +>this : Symbol(C, Decl(asyncArrowFunctionCapturesThis_es5.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types new file mode 100644 index 00000000000..da378ee2718 --- /dev/null +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts === +class C { +>C : C + + method() { +>method : () => void + + var fn = async () => await this; +>fn : () => Promise +>async () => await this : () => Promise +>await this : this +>this : this + } +} + diff --git a/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.errors.txt new file mode 100644 index 00000000000..7a35b1d5223 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclarationCapturesArguments_es5.ts(5,36): error TS2522: The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclarationCapturesArguments_es5.ts (1 errors) ==== + class C { + method() { + function other() {} + async function fn () { + await other.apply(this, arguments); + ~~~~~~~~~ +!!! error TS2522: The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method. + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js b/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js new file mode 100644 index 00000000000..8881ad555a7 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js @@ -0,0 +1,32 @@ +//// [asyncFunctionDeclarationCapturesArguments_es5.ts] +class C { + method() { + function other() {} + async function fn () { + await other.apply(this, arguments); + } + } +} + + +//// [asyncFunctionDeclarationCapturesArguments_es5.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + function other() { } + function fn() { + return __awaiter(this, arguments, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, other.apply(this, arguments)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + } + }; + return C; +}()); diff --git a/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.js b/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.js new file mode 100644 index 00000000000..20b0421d013 --- /dev/null +++ b/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.js @@ -0,0 +1,20 @@ +//// [asyncUnParenthesizedArrowFunction_es5.ts] + +declare function someOtherFunction(i: any): Promise; +const x = async i => await someOtherFunction(i) +const x1 = async (i) => await someOtherFunction(i); + +//// [asyncUnParenthesizedArrowFunction_es5.js] +var _this = this; +var x = function (i) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, someOtherFunction(i)]; + case 1: return [2 /*return*/, _a.sent()]; + } +}); }); }; +var x1 = function (i) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, someOtherFunction(i)]; + case 1: return [2 /*return*/, _a.sent()]; + } +}); }); }; diff --git a/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.symbols b/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.symbols new file mode 100644 index 00000000000..0f43ba7773e --- /dev/null +++ b/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncUnParenthesizedArrowFunction_es5.ts === + +declare function someOtherFunction(i: any): Promise; +>someOtherFunction : Symbol(someOtherFunction, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 0, 0)) +>i : Symbol(i, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 1, 35)) +>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +const x = async i => await someOtherFunction(i) +>x : Symbol(x, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 2, 5)) +>i : Symbol(i, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 2, 15)) +>someOtherFunction : Symbol(someOtherFunction, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 0, 0)) +>i : Symbol(i, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 2, 15)) + +const x1 = async (i) => await someOtherFunction(i); +>x1 : Symbol(x1, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 3, 5)) +>i : Symbol(i, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 3, 18)) +>someOtherFunction : Symbol(someOtherFunction, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 0, 0)) +>i : Symbol(i, Decl(asyncUnParenthesizedArrowFunction_es5.ts, 3, 18)) + diff --git a/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.types b/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.types new file mode 100644 index 00000000000..745c56cf09b --- /dev/null +++ b/tests/baselines/reference/asyncUnParenthesizedArrowFunction_es5.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncUnParenthesizedArrowFunction_es5.ts === + +declare function someOtherFunction(i: any): Promise; +>someOtherFunction : (i: any) => Promise +>i : any +>Promise : Promise + +const x = async i => await someOtherFunction(i) +>x : (i: any) => Promise +>async i => await someOtherFunction(i) : (i: any) => Promise +>i : any +>await someOtherFunction(i) : void +>someOtherFunction(i) : Promise +>someOtherFunction : (i: any) => Promise +>i : any + +const x1 = async (i) => await someOtherFunction(i); +>x1 : (i: any) => Promise +>async (i) => await someOtherFunction(i) : (i: any) => Promise +>i : any +>await someOtherFunction(i) : void +>someOtherFunction(i) : Promise +>someOtherFunction : (i: any) => Promise +>i : any + diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts new file mode 100644 index 00000000000..e6bb588b2b0 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +const x = async => async; \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts new file mode 100644 index 00000000000..14540c2a232 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts @@ -0,0 +1,8 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +var foo = async (): Promise => { + // Legal to use 'await' in a type context. + var v: await; +} diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts new file mode 100644 index 00000000000..d2aaea2a481 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +var foo = async (): Promise => { +}; \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts new file mode 100644 index 00000000000..120b5127a00 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +var f = (await) => { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts new file mode 100644 index 00000000000..810d7bc7e05 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +function f(await = await) { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts new file mode 100644 index 00000000000..e6b2bab3c79 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +var await = () => { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts new file mode 100644 index 00000000000..728e2e8ee72 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +var foo = async (await): Promise => { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts new file mode 100644 index 00000000000..41e26b2e695 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +var foo = async (a = await): Promise => { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts new file mode 100644 index 00000000000..f99ea629dd6 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts @@ -0,0 +1,9 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +var bar = async (): Promise => { + // 'await' here is an identifier, and not an await expression. + var foo = async (a = await): Promise => { + } +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts new file mode 100644 index 00000000000..4331a1c151a --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +var foo = async (): Promise => { + var v = { [await]: foo } +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts new file mode 100644 index 00000000000..7f1e072a3f2 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +var foo = async (a = await => await): Promise => { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts new file mode 100644 index 00000000000..4a800c1c2ce --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts @@ -0,0 +1,9 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +class C { + method() { + function other() {} + var fn = async () => await other.apply(this, arguments); + } +} diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts new file mode 100644 index 00000000000..e863af24490 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts @@ -0,0 +1,8 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +class C { + method() { + var fn = async () => await this; + } +} diff --git a/tests/cases/conformance/async/es5/asyncArrowFunction/asyncUnParenthesizedArrowFunction_es5.ts b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncUnParenthesizedArrowFunction_es5.ts new file mode 100644 index 00000000000..7db76c57084 --- /dev/null +++ b/tests/cases/conformance/async/es5/asyncArrowFunction/asyncUnParenthesizedArrowFunction_es5.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true + +declare function someOtherFunction(i: any): Promise; +const x = async i => await someOtherFunction(i) +const x1 = async (i) => await someOtherFunction(i); \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclarationCapturesArguments_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclarationCapturesArguments_es5.ts new file mode 100644 index 00000000000..b5c82688ddf --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclarationCapturesArguments_es5.ts @@ -0,0 +1,11 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +class C { + method() { + function other() {} + async function fn () { + await other.apply(this, arguments); + } + } +}