Skip to content

Commit b3ffd25

Browse files
committed
Disallowed for own in
1 parent 088b8b3 commit b3ffd25

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

lib/coffee-script/nodes.js

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

src/nodes.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,7 @@ exports.For = class For extends While
18371837
@pattern = @name instanceof Value
18381838
@index.error 'indexes do not apply to range loops' if @range and @index
18391839
@name.error 'cannot pattern match over range loops' if @range and @pattern
1840+
@index.error 'cannot use own with for-in' if @own and not @object
18401841
@returns = false
18411842

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

test/compilation.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@ test "#2846: while with empty body", ->
8181
CoffeeScript.compile 'while 1 then', {sourceMap: true}
8282

8383
test "#2944: implicit call with a regex argument", ->
84-
CoffeeScript.compile 'o[key] /regex/'
84+
CoffeeScript.compile 'o[key] /regex/'
85+
86+
test "#3001: `own` shouldn't be allowed in a `for`-`in` loop", ->
87+
cantCompile "a for own b in c"

test/comprehensions.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ test "#1910: loop index should be mutable within a loop iteration and immutable
473473

474474
arr = ([v, v + 1] for v in [0..5])
475475
iterations = 0
476-
for own [v0, v1], k in arr when v0
476+
for [v0, v1], k in arr when v0
477477
k += 3
478478
++iterations
479479
eq 6, k

0 commit comments

Comments
 (0)