Skip to content

Commit 91b2cf6

Browse files
author
Marc Häfner
committed
Don't parse for own ... in
1 parent f48aa44 commit 91b2cf6

File tree

5 files changed

+65
-61
lines changed

5 files changed

+65
-61
lines changed

lib/coffee-script/grammar.js

Lines changed: 27 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/nodes.js

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/parser.js

Lines changed: 29 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammar.coffee

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,9 @@ grammar =
450450

451451
ForBody: [
452452
o 'FOR Range', -> source: LOC(2) new Value($2)
453-
o 'ForStart ForSource', -> $2.own = $1.own; $2.name = $1[0]; $2.index = $1[1]; $2
454-
]
455-
456-
ForStart: [
457-
o 'FOR ForVariables', -> $2
458-
o 'FOR OWN ForVariables', -> $3.own = yes; $3
453+
o 'FOR ForVariables ForInSource', -> $3.name = $2[0]; $3.index = $2[1]; $3
454+
o 'FOR ForVariables ForOfSource', -> $3.name = $2[0]; $3.index = $2[1]; $3
455+
o 'FOR OWN ForVariables ForOfSource', -> $4.own = yes; $4.name = $3[0]; $5.index = $3[1]; $4
459456
]
460457

461458
# An array of all accepted values for a variable inside the loop.
@@ -478,16 +475,19 @@ grammar =
478475
# The source of a comprehension is an array or object with an optional guard
479476
# clause. If it's an array comprehension, you can also choose to step through
480477
# in fixed-size increments.
481-
ForSource: [
478+
ForInSource: [
482479
o 'FORIN Expression', -> source: $2
483-
o 'FOROF Expression', -> source: $2, object: yes
484480
o 'FORIN Expression WHEN Expression', -> source: $2, guard: $4
485-
o 'FOROF Expression WHEN Expression', -> source: $2, guard: $4, object: yes
486481
o 'FORIN Expression BY Expression', -> source: $2, step: $4
487482
o 'FORIN Expression WHEN Expression BY Expression', -> source: $2, guard: $4, step: $6
488483
o 'FORIN Expression BY Expression WHEN Expression', -> source: $2, step: $4, guard: $6
489484
]
490485

486+
ForOfSource: [
487+
o 'FOROF Expression', -> source: $2, object: yes
488+
o 'FOROF Expression WHEN Expression', -> source: $2, guard: $3, object: yes
489+
]
490+
491491
Switch: [
492492
o 'SWITCH Expression INDENT Whens OUTDENT', -> new Switch $2, $4
493493
o 'SWITCH Expression INDENT Whens ELSE Block OUTDENT', -> new Switch $2, $4, $6

src/nodes.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,6 @@ exports.For = class For extends While
18381838
@pattern = @name instanceof Value
18391839
@index.error 'indexes do not apply to range loops' if @range and @index
18401840
@name.error 'cannot pattern match over range loops' if @range and @pattern
1841-
@index.error 'cannot use own with for-in' if @own and not @object
18421841
@returns = false
18431842

18441843
children: ['body', 'source', 'guard', 'step']

0 commit comments

Comments
 (0)