improve elision output (#4824)

This commit is contained in:
zdenko 2017-12-11 00:22:34 +01:00 committed by Geoffrey Booth
parent 5eb9dded52
commit b1286752b9
3 changed files with 8 additions and 4 deletions

View File

@ -3626,7 +3626,10 @@
subpattern: true
}).compileToFragments(o, LEVEL_LIST));
} else {
assigns.push(idx.compileToFragments(o, LEVEL_LIST));
if (expandedIdx) {
// Output `Elision` only if `idx` is `i++`, e.g. expandedIdx.
assigns.push(idx.compileToFragments(o, LEVEL_LIST));
}
}
}
if (!(top || this.subpattern)) {

View File

@ -2472,7 +2472,8 @@ exports.Assign = class Assign extends Base
unless obj instanceof Elision
assigns.push new Assign(obj, val, null, param: @param, subpattern: yes).compileToFragments o, LEVEL_LIST
else
assigns.push idx.compileToFragments o, LEVEL_LIST
# Output `Elision` only if `idx` is `i++`, e.g. expandedIdx.
assigns.push idx.compileToFragments o, LEVEL_LIST if expandedIdx
assigns.push vvar unless top or @subpattern
fragments = @joinFragmentArrays assigns, ', '

View File

@ -74,8 +74,8 @@ test "array elisions destructuring with splats and expansions", ->
arrayEq [a,b], [2,[5,6,7,8,9]]
[,c,...,,d,,e] = arr
arrayEq [c,d,e], [2,7,9]
[...,e,,,f,,,] = arr
arrayEq [e,f], [4,7]
[...,f,,,g,,,] = arr
arrayEq [f,g], [4,7]
test "array elisions as function parameters", ->
arr = [1,2,3,4,5,6,7,8,9]