Skip to content

Commit 25fe126

Browse files
committed
fix: allow of as identifiers in for loops
1 parent 91e3f3f commit 25fe126

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

grammar.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ module.exports = grammar({
297297
),
298298

299299
variable_declarator: $ => seq(
300-
field('name', choice($.identifier, $._destructuring_pattern)),
300+
field('name', choice(
301+
$.identifier,
302+
alias('of', $.identifier),
303+
$._destructuring_pattern,
304+
)),
301305
optional($._initializer),
302306
),
303307

@@ -358,6 +362,7 @@ module.exports = grammar({
358362
field('kind', 'var'),
359363
field('left', choice(
360364
$.identifier,
365+
alias('of', $.identifier),
361366
$._destructuring_pattern,
362367
)),
363368
optional($._initializer),
@@ -366,6 +371,7 @@ module.exports = grammar({
366371
field('kind', choice('let', 'const')),
367372
field('left', choice(
368373
$.identifier,
374+
alias('of', $.identifier),
369375
$._destructuring_pattern,
370376
)),
371377
optional($._automatic_semicolon),
@@ -377,6 +383,7 @@ module.exports = grammar({
377383
)),
378384
field('left', choice(
379385
$.identifier,
386+
alias('of', $.identifier),
380387
$._destructuring_pattern,
381388
)),
382389
optional($._automatic_semicolon),

test/corpus/statements.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,33 @@ for await (await using resource of resources) {
935935
(arguments
936936
(identifier)))))))
937937

938+
============================================
939+
'of' as identifier in declarations
940+
============================================
941+
942+
for (let of of []) break;
943+
for (const of = '';;) break;
944+
const of = 2;
945+
946+
---
947+
948+
(program
949+
(for_in_statement
950+
(identifier)
951+
(array)
952+
(break_statement))
953+
(for_statement
954+
(lexical_declaration
955+
(variable_declarator
956+
(identifier)
957+
(string)))
958+
(empty_statement)
959+
(break_statement))
960+
(lexical_declaration
961+
(variable_declarator
962+
(identifier)
963+
(number))))
964+
938965
============================================
939966
Comments
940967
============================================

0 commit comments

Comments
 (0)