mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #3002 from Nami-Doc/issue3001
Disallowed `for own in`
This commit is contained in:
@@ -2584,6 +2584,9 @@
|
||||
if (this.range && this.pattern) {
|
||||
this.name.error('cannot pattern match over range loops');
|
||||
}
|
||||
if (this.own && !this.object) {
|
||||
this.index.error('cannot use own with for-in');
|
||||
}
|
||||
this.returns = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1837,6 +1837,7 @@ exports.For = class For extends While
|
||||
@pattern = @name instanceof Value
|
||||
@index.error 'indexes do not apply to range loops' if @range and @index
|
||||
@name.error 'cannot pattern match over range loops' if @range and @pattern
|
||||
@index.error 'cannot use own with for-in' if @own and not @object
|
||||
@returns = false
|
||||
|
||||
children: ['body', 'source', 'guard', 'step']
|
||||
|
||||
@@ -81,4 +81,7 @@ test "#2846: while with empty body", ->
|
||||
CoffeeScript.compile 'while 1 then', {sourceMap: true}
|
||||
|
||||
test "#2944: implicit call with a regex argument", ->
|
||||
CoffeeScript.compile 'o[key] /regex/'
|
||||
CoffeeScript.compile 'o[key] /regex/'
|
||||
|
||||
test "#3001: `own` shouldn't be allowed in a `for`-`in` loop", ->
|
||||
cantCompile "a for own b in c"
|
||||
@@ -473,7 +473,7 @@ test "#1910: loop index should be mutable within a loop iteration and immutable
|
||||
|
||||
arr = ([v, v + 1] for v in [0..5])
|
||||
iterations = 0
|
||||
for own [v0, v1], k in arr when v0
|
||||
for [v0, v1], k in arr when v0
|
||||
k += 3
|
||||
++iterations
|
||||
eq 6, k
|
||||
|
||||
Reference in New Issue
Block a user