diff --git a/CHANGELOG.md b/CHANGELOG.md index 8110444137..9a75efd12a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.13.4 + + * Fix single spread element returning itself. + # 1.13.3 * Upgrade `acorn-6to5`. diff --git a/lib/6to5/transformation/transformers/es6-spread.js b/lib/6to5/transformation/transformers/es6-spread.js index f54a3a417b..20f2165bda 100644 --- a/lib/6to5/transformation/transformers/es6-spread.js +++ b/lib/6to5/transformation/transformers/es6-spread.js @@ -48,7 +48,10 @@ exports.ArrayExpression = function (node, parent, file) { var nodes = build(elements, file); var first = nodes.shift(); - if (!nodes.length) return first; + if (!t.isArrayExpression(first)) { + nodes.unshift(first); + first = t.arrayExpression([]); + } return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes); }; diff --git a/test/fixtures/transformation/es6-spread/array-literal-first/expected.js b/test/fixtures/transformation/es6-spread/array-literal-first/expected.js index a07cb0411f..05d2c2e6f8 100644 --- a/test/fixtures/transformation/es6-spread/array-literal-first/expected.js +++ b/test/fixtures/transformation/es6-spread/array-literal-first/expected.js @@ -4,4 +4,4 @@ var _toArray = function (arr) { return Array.isArray(arr) ? arr : Array.from(arr); }; -var lyrics = _toArray(parts).concat(["head", "and", "toes"]); +var lyrics = [].concat(_toArray(parts), ["head", "and", "toes"]); diff --git a/test/fixtures/transformation/es6-spread/single/expected.js b/test/fixtures/transformation/es6-spread/single/expected.js index 8c8592f34d..d928b5e845 100644 --- a/test/fixtures/transformation/es6-spread/single/expected.js +++ b/test/fixtures/transformation/es6-spread/single/expected.js @@ -4,4 +4,4 @@ var _toArray = function (arr) { return Array.isArray(arr) ? arr : Array.from(arr); }; -_toArray(foo); +[].concat(_toArray(foo));