Skip to content

Commit

Permalink
Merge pull request #3327 from xixixao/forexpansion
Browse files Browse the repository at this point in the history
Fix expansion in destructuring inside comprehensions
  • Loading branch information
jashkenas committed Jan 24, 2014
2 parents daa6ad5 + bd6b414 commit 6bdd527
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ exports.For = class For extends While
@returns = no if lastJumps and lastJumps instanceof Return
source = if @range then @source.base else @source
scope = o.scope
name = @name and (@name.compile o, LEVEL_LIST)
name = @name and (@name.compile o, LEVEL_LIST) if not @pattern
index = @index and (@index.compile o, LEVEL_LIST)
scope.find(name) if name and not @pattern
scope.find(index) if index
Expand Down
9 changes: 6 additions & 3 deletions test/comprehensions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ test "#2525, #1187, #1208, #1758, looping over an array backwards", ->

arrayEq (index for i, index in list by ident(-1) * 2), [4, 2, 0]

test "splats in destructuring in comprehensions", ->
list = [[0, 1, 2], [2, 3, 4], [4, 5, 6]]
arrayEq (seq for [rep, seq...] in list), [[1, 2], [3, 4], [5, 6]]




test "#156: expansion in destructuring in comprehensions", ->
list = [[0, 1, 2], [2, 3, 4], [4, 5, 6]]
arrayEq (last for [..., last] in list), [2, 4, 6]

0 comments on commit 6bdd527

Please sign in to comment.