Skip to content

Commit c6f768a

Browse files
authored
[javascript]: Allow only single variable bindings in for in and for of loops (#4625)
* [javascript]: Allow only single variable bindings in `for in` and `for of` loops * [javascript]: Align misaligned labels
1 parent a5754dd commit c6f768a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

javascript/javascript/JavaScriptParser.g4

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ variableDeclarationList
157157
: varModifier variableDeclaration (',' variableDeclaration)*
158158
;
159159

160+
singleVariableDeclaration
161+
: varModifier variableDeclaration
162+
;
163+
160164
variableDeclaration
161165
: assignable ('=' singleExpression)? // ECMAScript 6: Array & Object Matching
162166
;
@@ -177,8 +181,8 @@ iterationStatement
177181
: Do statement While '(' expressionSequence ')' eos # DoStatement
178182
| While '(' expressionSequence ')' statement # WhileStatement
179183
| For '(' (expressionSequence | variableDeclarationList)? ';' expressionSequence? ';' expressionSequence? ')' statement # ForStatement
180-
| For '(' (singleExpression | variableDeclarationList) In expressionSequence ')' statement # ForInStatement
181-
| For Await? '(' (singleExpression | variableDeclarationList) Of expressionSequence ')' statement # ForOfStatement
184+
| For '(' (singleExpression | singleVariableDeclaration) In expressionSequence ')' statement # ForInStatement
185+
| For Await? '(' (singleExpression | singleVariableDeclaration) Of expressionSequence ')' statement # ForOfStatement
182186
;
183187

184188
varModifier // let, const - ECMAScript 6
@@ -559,7 +563,7 @@ keyword
559563
| Protected
560564
| Static
561565
| Yield
562-
| YieldStar
566+
| YieldStar
563567
| Async
564568
| Await
565569
| From

0 commit comments

Comments
 (0)