From b1286752b9f6ccfba9c9c9f05b0e3d52aad835c2 Mon Sep 17 00:00:00 2001 From: zdenko Date: Mon, 11 Dec 2017 00:22:34 +0100 Subject: [PATCH] improve elision output (#4824) --- lib/coffeescript/nodes.js | 5 ++++- src/nodes.coffee | 3 ++- test/arrays.coffee | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/coffeescript/nodes.js b/lib/coffeescript/nodes.js index 6a5b69b5..3b6f09b7 100644 --- a/lib/coffeescript/nodes.js +++ b/lib/coffeescript/nodes.js @@ -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)) { diff --git a/src/nodes.coffee b/src/nodes.coffee index 63914af3..4dc67a7c 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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, ', ' diff --git a/test/arrays.coffee b/test/arrays.coffee index 37f8c493..a8b8db06 100644 --- a/test/arrays.coffee +++ b/test/arrays.coffee @@ -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]