diff --git a/lib/6to5/transformers/destructuring.js b/lib/6to5/transformers/destructuring.js index c9330b819b..05bf35f085 100644 --- a/lib/6to5/transformers/destructuring.js +++ b/lib/6to5/transformers/destructuring.js @@ -40,7 +40,15 @@ var pushArrayPattern = function (kind, nodes, pattern, parentId) { _.each(pattern.elements, function (elem, i) { if (!elem) return; - var newPatternId = t.memberExpression(parentId, t.literal(i), true); + var newPatternId; + + if (t.isSpreadElement(elem)) { + newPatternId = t.callExpression(t.memberExpression(parentId, t.identifier("slice")), [t.literal(i)]); + elem = elem.argument; + } else { + newPatternId = t.memberExpression(parentId, t.literal(i), true); + } + push(kind, nodes, elem, newPatternId); }); }; diff --git a/test/fixtures/transformation/destructuring/spread/actual.js b/test/fixtures/transformation/destructuring/spread/actual.js new file mode 100644 index 0000000000..0ef8f028ed --- /dev/null +++ b/test/fixtures/transformation/destructuring/spread/actual.js @@ -0,0 +1,5 @@ +var isSorted = ([x, y, ...wow]) => { + if (!zs.length) return true + if (y > x) return isSorted(zs) + return false +}; diff --git a/test/fixtures/transformation/destructuring/spread/expected.js b/test/fixtures/transformation/destructuring/spread/expected.js new file mode 100644 index 0000000000..8802adf2b1 --- /dev/null +++ b/test/fixtures/transformation/destructuring/spread/expected.js @@ -0,0 +1,11 @@ +"use strict"; + +var isSorted = function (_ref) { + var x = _ref[0]; + var y = _ref[1]; + var wow = _ref.slice(2); + + if (!zs.length) return true; + if (y > x) return isSorted(zs); + return false; +};