Skip to content

Commit a591ca3

Browse files
authored
fix(61747): for (using of = is incorrectly parsed (#61764)
1 parent 2b88aeb commit a591ca3

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/compiler/parser.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7328,9 +7328,16 @@ namespace Parser {
73287328
return nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine(/*disallowOf*/ true);
73297329
}
73307330

7331+
function nextTokenIsEqualsOrSemicolonOrColonToken() {
7332+
nextToken();
7333+
return token() === SyntaxKind.EqualsToken || token() === SyntaxKind.SemicolonToken || token() === SyntaxKind.ColonToken;
7334+
}
7335+
73317336
function nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine(disallowOf?: boolean) {
73327337
nextToken();
7333-
if (disallowOf && token() === SyntaxKind.OfKeyword) return false;
7338+
if (disallowOf && token() === SyntaxKind.OfKeyword) {
7339+
return lookAhead(nextTokenIsEqualsOrSemicolonOrColonToken);
7340+
}
73347341
return (isBindingIdentifier() || token() === SyntaxKind.OpenBraceToken) && !scanner.hasPrecedingLineBreak();
73357342
}
73367343

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
usingDeclarationsInForOf.4.ts(3,12): error TS1155: 'using' declarations must be initialized.
2+
3+
4+
==== usingDeclarationsInForOf.4.ts (1 errors) ====
5+
for (using of = null;;) break;
6+
for (using of: null = null;;) break;
7+
for (using of;;) break;
8+
~~
9+
!!! error TS1155: 'using' declarations must be initialized.
10+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsInForOf.4.ts] ////
2+
3+
//// [usingDeclarationsInForOf.4.ts]
4+
for (using of = null;;) break;
5+
for (using of: null = null;;) break;
6+
for (using of;;) break;
7+
8+
9+
//// [usingDeclarationsInForOf.4.js]
10+
for (using of = null;;)
11+
break;
12+
for (using of = null;;)
13+
break;
14+
for (using of;;)
15+
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: esnext
2+
// @module: esnext
3+
// @lib: esnext
4+
// @noTypesAndSymbols: true
5+
6+
for (using of = null;;) break;
7+
for (using of: null = null;;) break;
8+
for (using of;;) break;

0 commit comments

Comments
 (0)