mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fix expansion in destructuring inside comprehensions
This commit is contained in:
parent
daa6ad5470
commit
bd6b4142fe
3 changed files with 11 additions and 5 deletions
|
@ -2144,6 +2144,7 @@
|
|||
Expansion.prototype.isComplex = NO;
|
||||
|
||||
Expansion.prototype.compileNode = function(o) {
|
||||
throw new Error;
|
||||
return this.error('Expansion must be used inside a destructuring assignment or parameter list');
|
||||
};
|
||||
|
||||
|
@ -2679,7 +2680,9 @@
|
|||
}
|
||||
source = this.range ? this.source.base : this.source;
|
||||
scope = o.scope;
|
||||
name = this.name && (this.name.compile(o, LEVEL_LIST));
|
||||
if (!this.pattern) {
|
||||
name = this.name && (this.name.compile(o, LEVEL_LIST));
|
||||
}
|
||||
index = this.index && (this.index.compile(o, LEVEL_LIST));
|
||||
if (name && !this.pattern) {
|
||||
scope.find(name);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue