Skip to content

Commit

Permalink
fix(43879): forbid async in the left hand in a for-of statement
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed May 8, 2021
1 parent 3e25424 commit 16b17c8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41471,6 +41471,12 @@ namespace ts {
}
}

if (isForOfStatement(forInOrOfStatement) && !(forInOrOfStatement.flags & NodeFlags.AwaitContext) &&
isIdentifier(forInOrOfStatement.initializer) && forInOrOfStatement.initializer.escapedText === "async") {
grammarErrorOnNode(forInOrOfStatement.initializer, Diagnostics.The_left_hand_side_of_a_for_of_statement_may_not_be_async);
return false;
}

if (forInOrOfStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
const variableList = <VariableDeclarationList>forInOrOfStatement.initializer;
if (!checkGrammarVariableDeclarationList(variableList)) {
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@
"category": "Error",
"code": 1105
},
"The left-hand side of a for-of statement may not be 'async'.": {
"category": "Error",
"code": 1106
},
"Jump target cannot cross function boundary.": {
"category": "Error",
"code": 1107
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/parserForOfStatement22.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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'.


==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts (1 errors) ====
var async;
for (async of [1, 2]) {}
~~~~~
!!! error TS1106: The left-hand side of a for-of statement may not be 'async'.

8 changes: 8 additions & 0 deletions tests/baselines/reference/parserForOfStatement22.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [parserForOfStatement22.ts]
var async;
for (async of [1, 2]) {}


//// [parserForOfStatement22.js]
var async;
for (async of [1, 2]) { }
7 changes: 7 additions & 0 deletions tests/baselines/reference/parserForOfStatement22.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts ===
var async;
>async : Symbol(async, Decl(parserForOfStatement22.ts, 0, 3))

for (async of [1, 2]) {}
>async : Symbol(async, Decl(parserForOfStatement22.ts, 0, 3))

10 changes: 10 additions & 0 deletions tests/baselines/reference/parserForOfStatement22.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement22.ts ===
var async;
>async : any

for (async of [1, 2]) {}
>async : any
>[1, 2] : number[]
>1 : 1
>2 : 2

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @target: esnext

var async;
for (async of [1, 2]) {}

0 comments on commit 16b17c8

Please sign in to comment.