improve elision output (#4824)
This commit is contained in:
parent
5eb9dded52
commit
b1286752b9
|
@ -3626,7 +3626,10 @@
|
||||||
subpattern: true
|
subpattern: true
|
||||||
}).compileToFragments(o, LEVEL_LIST));
|
}).compileToFragments(o, LEVEL_LIST));
|
||||||
} else {
|
} 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)) {
|
if (!(top || this.subpattern)) {
|
||||||
|
|
|
@ -2472,7 +2472,8 @@ exports.Assign = class Assign extends Base
|
||||||
unless obj instanceof Elision
|
unless obj instanceof Elision
|
||||||
assigns.push new Assign(obj, val, null, param: @param, subpattern: yes).compileToFragments o, LEVEL_LIST
|
assigns.push new Assign(obj, val, null, param: @param, subpattern: yes).compileToFragments o, LEVEL_LIST
|
||||||
else
|
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
|
assigns.push vvar unless top or @subpattern
|
||||||
fragments = @joinFragmentArrays assigns, ', '
|
fragments = @joinFragmentArrays assigns, ', '
|
||||||
|
|
|
@ -74,8 +74,8 @@ test "array elisions destructuring with splats and expansions", ->
|
||||||
arrayEq [a,b], [2,[5,6,7,8,9]]
|
arrayEq [a,b], [2,[5,6,7,8,9]]
|
||||||
[,c,...,,d,,e] = arr
|
[,c,...,,d,,e] = arr
|
||||||
arrayEq [c,d,e], [2,7,9]
|
arrayEq [c,d,e], [2,7,9]
|
||||||
[...,e,,,f,,,] = arr
|
[...,f,,,g,,,] = arr
|
||||||
arrayEq [e,f], [4,7]
|
arrayEq [f,g], [4,7]
|
||||||
|
|
||||||
test "array elisions as function parameters", ->
|
test "array elisions as function parameters", ->
|
||||||
arr = [1,2,3,4,5,6,7,8,9]
|
arr = [1,2,3,4,5,6,7,8,9]
|
||||||
|
|
Loading…
Reference in New Issue