Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(43879): for ( async of should be a syntax error #43886

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) &&
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 8 additions & 0 deletions tests/baselines/reference/for-inStatementsAsyncIdentifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [for-inStatementsAsyncIdentifier.ts]
var async;
for (async in { a: 1, b: 2 }) {}


//// [for-inStatementsAsyncIdentifier.js]
var async;
for (async in { a: 1, b: 2 }) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/conformance/statements/for-inStatements/for-inStatementsAsyncIdentifier.ts ===
var async;
>async : Symbol(async, Decl(for-inStatementsAsyncIdentifier.ts, 0, 3))

for (async in { a: 1, b: 2 }) {}
>async : Symbol(async, Decl(for-inStatementsAsyncIdentifier.ts, 0, 3))
>a : Symbol(a, Decl(for-inStatementsAsyncIdentifier.ts, 1, 15))
>b : Symbol(b, Decl(for-inStatementsAsyncIdentifier.ts, 1, 21))

12 changes: 12 additions & 0 deletions tests/baselines/reference/for-inStatementsAsyncIdentifier.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/conformance/statements/for-inStatements/for-inStatementsAsyncIdentifier.ts ===
var async;
>async : any

for (async in { a: 1, b: 2 }) {}
>async : any
>{ a: 1, b: 2 } : { a: number; b: number; }
>a : number
>1 : 1
>b : number
>2 : 2

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

12 changes: 12 additions & 0 deletions tests/baselines/reference/parserForOfStatement23.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [parserForOfStatement23.ts]
async function foo(x: any) {
var async;
for await (async of x) {}
}


//// [parserForOfStatement23.js]
async function foo(x) {
var async;
for await (async of x) { }
}
13 changes: 13 additions & 0 deletions tests/baselines/reference/parserForOfStatement23.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement23.ts ===
async function foo(x: any) {
>foo : Symbol(foo, Decl(parserForOfStatement23.ts, 0, 0))
>x : Symbol(x, Decl(parserForOfStatement23.ts, 0, 19))

var async;
>async : Symbol(async, Decl(parserForOfStatement23.ts, 1, 7))

for await (async of x) {}
>async : Symbol(async, Decl(parserForOfStatement23.ts, 1, 7))
>x : Symbol(x, Decl(parserForOfStatement23.ts, 0, 19))
}

13 changes: 13 additions & 0 deletions tests/baselines/reference/parserForOfStatement23.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement23.ts ===
async function foo(x: any) {
>foo : (x: any) => Promise<void>
>x : any

var async;
>async : any

for await (async of x) {}
>async : any
>x : any
}

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


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

for ((async) of [1, 2]);
>async : Symbol(async, Decl(parserForOfStatement24.ts, 0, 3))

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

for ((async) of [1, 2]);
>(async) : any
>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
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved

var async;
for (async of [1, 2]) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @target: esnext

async function foo(x: any) {
var async;
for await (async of x) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @target: esnext

var async;
for ((async) of [1, 2]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @target: esnext

var async;
for (async in { a: 1, b: 2 }) {}