Skip to content

Commit 0423c39

Browse files
committed
fix(43879): forbid async in the left hand in a for-of statement
1 parent 3e25424 commit 0423c39

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41471,6 +41471,11 @@ namespace ts {
4147141471
}
4147241472
}
4147341473

41474+
if (isForOfStatement(forInOrOfStatement) && isIdentifier(forInOrOfStatement.initializer) && forInOrOfStatement.initializer.escapedText === "async") {
41475+
grammarErrorOnNode(forInOrOfStatement.initializer, Diagnostics.The_left_hand_side_of_a_for_of_statement_may_not_be_async);
41476+
return false;
41477+
}
41478+
4147441479
if (forInOrOfStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
4147541480
const variableList = <VariableDeclarationList>forInOrOfStatement.initializer;
4147641481
if (!checkGrammarVariableDeclarationList(variableList)) {

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@
319319
"category": "Error",
320320
"code": 1105
321321
},
322+
"The left-hand side of a for-of statement may not be 'async'.": {
323+
"category": "Error",
324+
"code": 1106
325+
},
322326
"Jump target cannot cross function boundary.": {
323327
"category": "Error",
324328
"code": 1107
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts(2,6): error TS1106: The left-hand side of a for-of statement may not be 'async'.
2+
3+
4+
==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts (1 errors) ====
5+
var async;
6+
for (async of [1, 2]) {}
7+
~~~~~
8+
!!! error TS1106: The left-hand side of a for-of statement may not be 'async'.
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [parserForOfStatement22.ts]
2+
var async;
3+
for (async of [1, 2]) {}
4+
5+
6+
//// [parserForOfStatement22.js]
7+
var async;
8+
for (async of [1, 2]) { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts ===
2+
var async;
3+
>async : Symbol(async, Decl(parserForOfStatement22.ts, 0, 3))
4+
5+
for (async of [1, 2]) {}
6+
>async : Symbol(async, Decl(parserForOfStatement22.ts, 0, 3))
7+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts ===
2+
var async;
3+
>async : any
4+
5+
for (async of [1, 2]) {}
6+
>async : any
7+
>[1, 2] : number[]
8+
>1 : 1
9+
>2 : 2
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @target: esnext
2+
3+
var async;
4+
for (async of [1, 2]) {}

0 commit comments

Comments
 (0)