mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Allow of in await using declarations in for-of loops (#55558)
This commit is contained in:
committed by
GitHub
parent
42d0e5100f
commit
3e12250839
@@ -6892,7 +6892,8 @@ namespace Parser {
|
||||
if (
|
||||
token() === SyntaxKind.VarKeyword || token() === SyntaxKind.LetKeyword || token() === SyntaxKind.ConstKeyword ||
|
||||
token() === SyntaxKind.UsingKeyword && lookAhead(nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLineDisallowOf) ||
|
||||
token() === SyntaxKind.AwaitKeyword && lookAhead(nextTokenIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLineDisallowOf)
|
||||
// this one is meant to allow of
|
||||
token() === SyntaxKind.AwaitKeyword && lookAhead(nextTokenIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLine)
|
||||
) {
|
||||
initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true);
|
||||
}
|
||||
@@ -7308,10 +7309,6 @@ namespace Parser {
|
||||
return lookAhead(nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine);
|
||||
}
|
||||
|
||||
function nextTokenIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLineDisallowOf() {
|
||||
return nextTokenIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLine(/*disallowOf*/ true);
|
||||
}
|
||||
|
||||
function nextTokenIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLine(disallowOf?: boolean) {
|
||||
if (nextToken() === SyntaxKind.UsingKeyword) {
|
||||
return nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine(disallowOf);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
awaitUsingDeclarationsInForAwaitOf.2.ts(4,32): error TS2448: Block-scoped variable 'of' used before its declaration.
|
||||
|
||||
|
||||
==== awaitUsingDeclarationsInForAwaitOf.2.ts (1 errors) ====
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
|
||||
async function test() {
|
||||
for await (await using of of of) {};
|
||||
~~
|
||||
!!! error TS2448: Block-scoped variable 'of' used before its declaration.
|
||||
!!! related TS2728 awaitUsingDeclarationsInForAwaitOf.2.ts:4:26: 'of' is declared here.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForAwaitOf.2.ts] ////
|
||||
|
||||
//// [awaitUsingDeclarationsInForAwaitOf.2.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
|
||||
async function test() {
|
||||
for await (await using of of of) {};
|
||||
}
|
||||
|
||||
|
||||
//// [awaitUsingDeclarationsInForAwaitOf.2.js]
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
async function test() {
|
||||
for await (await using of of of) { }
|
||||
;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
awaitUsingDeclarationsInForOf.2.ts(2,10): error TS2487: The left-hand side of a 'for...of' statement must be a variable or a property access.
|
||||
awaitUsingDeclarationsInForOf.2.ts(2,16): error TS2304: Cannot find name 'using'.
|
||||
awaitUsingDeclarationsInForOf.2.ts(2,25): error TS2304: Cannot find name 'of'.
|
||||
awaitUsingDeclarationsInForOf.2.ts(2,29): error TS1011: An element access expression should take an argument.
|
||||
|
||||
|
||||
==== awaitUsingDeclarationsInForOf.2.ts (4 errors) ====
|
||||
async function main() {
|
||||
for (await using of of []) {
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2487: The left-hand side of a 'for...of' statement must be a variable or a property access.
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'using'.
|
||||
~~
|
||||
!!! error TS2304: Cannot find name 'of'.
|
||||
|
||||
!!! error TS1011: An element access expression should take an argument.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ async function main() {
|
||||
|
||||
//// [awaitUsingDeclarationsInForOf.2.js]
|
||||
async function main() {
|
||||
for (await using of of[]) {
|
||||
for (await using of of []) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
awaitUsingDeclarationsInForOf.4.ts(4,8): error TS2853: 'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
|
||||
awaitUsingDeclarationsInForOf.4.ts(4,26): error TS2448: Block-scoped variable 'of' used before its declaration.
|
||||
|
||||
|
||||
==== awaitUsingDeclarationsInForOf.4.ts (2 errors) ====
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
|
||||
{
|
||||
for (await using of of of) {};
|
||||
~~~~~
|
||||
!!! error TS2853: 'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
|
||||
~~
|
||||
!!! error TS2448: Block-scoped variable 'of' used before its declaration.
|
||||
!!! related TS2728 awaitUsingDeclarationsInForOf.4.ts:4:20: 'of' is declared here.
|
||||
}
|
||||
|
||||
16
tests/baselines/reference/awaitUsingDeclarationsInForOf.4.js
Normal file
16
tests/baselines/reference/awaitUsingDeclarationsInForOf.4.js
Normal file
@@ -0,0 +1,16 @@
|
||||
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForOf.4.ts] ////
|
||||
|
||||
//// [awaitUsingDeclarationsInForOf.4.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
|
||||
{
|
||||
for (await using of of of) {};
|
||||
}
|
||||
|
||||
|
||||
//// [awaitUsingDeclarationsInForOf.4.js]
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
{
|
||||
for (await using of of of) { }
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// @target: esnext
|
||||
// @module: esnext
|
||||
// @lib: esnext
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
|
||||
async function test() {
|
||||
for await (await using of of of) {};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// @target: esnext
|
||||
// @module: esnext
|
||||
// @lib: esnext
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/55555
|
||||
|
||||
{
|
||||
for (await using of of of) {};
|
||||
}
|
||||
Reference in New Issue
Block a user