Skip to content

Commit 644e4da

Browse files
committed
Added es5 conformance tests for async arrow functions, add error for referencing 'arguments' in a generator.
1 parent 203dab4 commit 644e4da

File tree

53 files changed

+596
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+596
-3
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8162,10 +8162,13 @@ namespace ts {
81628162
// can explicitly bound arguments objects
81638163
if (symbol === argumentsSymbol) {
81648164
const container = getContainingFunction(node);
8165-
if (container.kind === SyntaxKind.ArrowFunction) {
8166-
if (languageVersion < ScriptTarget.ES6) {
8165+
if (languageVersion < ScriptTarget.ES6) {
8166+
if (container.kind === SyntaxKind.ArrowFunction) {
81678167
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
81688168
}
8169+
else if (hasModifier(container, ModifierFlags.Async)) {
8170+
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);
8171+
}
81698172
}
81708173

81718174
if (node.flags & NodeFlags.AwaitContext) {

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@
16951695
"category": "Error",
16961696
"code": 2521
16971697
},
1698-
"The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression.": {
1698+
"The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method.": {
16991699
"category": "Error",
17001700
"code": 2522
17011701
},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [arrowFunctionWithParameterNameAsync_es5.ts]
2+
3+
const x = async => async;
4+
5+
//// [arrowFunctionWithParameterNameAsync_es5.js]
6+
var x = function (async) { return async; };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts ===
2+
3+
const x = async => async;
4+
>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 5))
5+
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 9))
6+
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 9))
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts ===
2+
3+
const x = async => async;
4+
>x : (async: any) => any
5+
>async => async : (async: any) => any
6+
>async : any
7+
>async : any
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts(4,11): error TS2304: Cannot find name 'await'.
2+
3+
4+
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts (1 errors) ====
5+
6+
var foo = async (): Promise<void> => {
7+
// Legal to use 'await' in a type context.
8+
var v: await;
9+
~~~~~
10+
!!! error TS2304: Cannot find name 'await'.
11+
}
12+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [asyncArrowFunction10_es5.ts]
2+
3+
var foo = async (): Promise<void> => {
4+
// Legal to use 'await' in a type context.
5+
var v: await;
6+
}
7+
8+
9+
//// [asyncArrowFunction10_es5.js]
10+
var _this = this;
11+
var foo = function () { return __awaiter(_this, void 0, void 0, function () {
12+
var v;
13+
return __generator(this, function (_a) {
14+
return [2 /*return*/];
15+
});
16+
}); };
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [asyncArrowFunction1_es5.ts]
2+
3+
var foo = async (): Promise<void> => {
4+
};
5+
6+
//// [asyncArrowFunction1_es5.js]
7+
var _this = this;
8+
var foo = function () { return __awaiter(_this, void 0, void 0, function () {
9+
return __generator(this, function (_a) {
10+
return [2 /*return*/];
11+
});
12+
}); };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts ===
2+
3+
var foo = async (): Promise<void> => {
4+
>foo : Symbol(foo, Decl(asyncArrowFunction1_es5.ts, 1, 3))
5+
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
6+
7+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts ===
2+
3+
var foo = async (): Promise<void> => {
4+
>foo : () => Promise<void>
5+
>async (): Promise<void> => {} : () => Promise<void>
6+
>Promise : Promise<T>
7+
8+
};

0 commit comments

Comments
 (0)