fix spread not returning a new array with a single spread element

This commit is contained in:
Sebastian McKenzie 2014-11-23 20:16:10 +11:00
parent 1de4893a69
commit 3396cc84f1
4 changed files with 10 additions and 3 deletions

View File

@ -1,3 +1,7 @@
# 1.13.4
* Fix single spread element returning itself.
# 1.13.3 # 1.13.3
* Upgrade `acorn-6to5`. * Upgrade `acorn-6to5`.

View File

@ -48,7 +48,10 @@ exports.ArrayExpression = function (node, parent, file) {
var nodes = build(elements, file); var nodes = build(elements, file);
var first = nodes.shift(); 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); return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
}; };

View File

@ -4,4 +4,4 @@ var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(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"]);

View File

@ -4,4 +4,4 @@ var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr); return Array.isArray(arr) ? arr : Array.from(arr);
}; };
_toArray(foo); [].concat(_toArray(foo));