Skip to content

Commit 6bdd527

Browse files
committed
Merge pull request #3327 from xixixao/forexpansion
Fix expansion in destructuring inside comprehensions
2 parents daa6ad5 + bd6b414 commit 6bdd527

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/coffee-script/nodes.js

Lines changed: 4 additions & 1 deletion
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ exports.For = class For extends While
19141914
@returns = no if lastJumps and lastJumps instanceof Return
19151915
source = if @range then @source.base else @source
19161916
scope = o.scope
1917-
name = @name and (@name.compile o, LEVEL_LIST)
1917+
name = @name and (@name.compile o, LEVEL_LIST) if not @pattern
19181918
index = @index and (@index.compile o, LEVEL_LIST)
19191919
scope.find(name) if name and not @pattern
19201920
scope.find(index) if index

test/comprehensions.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ test "#2525, #1187, #1208, #1758, looping over an array backwards", ->
537537

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

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

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

0 commit comments

Comments
 (0)