Fixes #2274 -- allow @variables as loop variables

This commit is contained in:
Jeremy Ashkenas 2012-04-24 12:21:47 -04:00
parent c06487c13b
commit 4fc9a345bb
4 changed files with 213 additions and 113 deletions

View File

@ -413,7 +413,7 @@
})
],
ForValue: [
o('Identifier'), o('Array', function() {
o('Identifier'), o('ThisProperty'), o('Array', function() {
return new Value($1);
}), o('Object', function() {
return new Value($1);

File diff suppressed because one or more lines are too long

View File

@ -443,6 +443,7 @@ grammar =
# This enables support for pattern matching.
ForValue: [
o 'Identifier'
o 'ThisProperty'
o 'Array', -> new Value $1
o 'Object', -> new Value $1
]

View File

@ -499,3 +499,14 @@ test "#2007: Return object literal from comprehension", ->
eq 2, y.length
eq 1, y[0].x
eq 0, y[1].x
test "#2274: Allow @values as loop variables", ->
obj = {
item: null
method: ->
for @item in [1, 2, 3]
null
}
eq obj.item, null
obj.method()
eq obj.item, 3