fix(43879): forbid async in the left hand in a for-of statement (#43886)
This commit is contained in:
parent
463c79440f
commit
7aacd6b274
|
@ -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)) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }) { }
|
|
@ -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))
|
||||
|
|
@ -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
|
||||
|
|
@ -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
tests/baselines/reference/parserForOfStatement22.js
Normal file
8
tests/baselines/reference/parserForOfStatement22.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
//// [parserForOfStatement22.ts]
|
||||
var async;
|
||||
for (async of [1, 2]) {}
|
||||
|
||||
|
||||
//// [parserForOfStatement22.js]
|
||||
var async;
|
||||
for (async of [1, 2]) { }
|
7
tests/baselines/reference/parserForOfStatement22.symbols
Normal file
7
tests/baselines/reference/parserForOfStatement22.symbols
Normal file
|
@ -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
tests/baselines/reference/parserForOfStatement22.types
Normal file
10
tests/baselines/reference/parserForOfStatement22.types
Normal file
|
@ -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
tests/baselines/reference/parserForOfStatement23.js
Normal file
12
tests/baselines/reference/parserForOfStatement23.js
Normal file
|
@ -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
tests/baselines/reference/parserForOfStatement23.symbols
Normal file
13
tests/baselines/reference/parserForOfStatement23.symbols
Normal file
|
@ -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
tests/baselines/reference/parserForOfStatement23.types
Normal file
13
tests/baselines/reference/parserForOfStatement23.types
Normal file
|
@ -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
tests/baselines/reference/parserForOfStatement24.js
Normal file
9
tests/baselines/reference/parserForOfStatement24.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
//// [parserForOfStatement24.ts]
|
||||
var async;
|
||||
for ((async) of [1, 2]);
|
||||
|
||||
|
||||
//// [parserForOfStatement24.js]
|
||||
var async;
|
||||
for ((async) of [1, 2])
|
||||
;
|
7
tests/baselines/reference/parserForOfStatement24.symbols
Normal file
7
tests/baselines/reference/parserForOfStatement24.symbols
Normal file
|
@ -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
tests/baselines/reference/parserForOfStatement24.types
Normal file
11
tests/baselines/reference/parserForOfStatement24.types
Normal file
|
@ -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
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// @target: esnext
|
||||
|
||||
var async;
|
||||
for (async of [1, 2]) {}
|
|
@ -0,0 +1,6 @@
|
|||
// @target: esnext
|
||||
|
||||
async function foo(x: any) {
|
||||
var async;
|
||||
for await (async of x) {}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
// @target: esnext
|
||||
|
||||
var async;
|
||||
for ((async) of [1, 2]);
|
|
@ -0,0 +1,4 @@
|
|||
// @target: esnext
|
||||
|
||||
var async;
|
||||
for (async in { a: 1, b: 2 }) {}
|
Loading…
Reference in a new issue