No unneeded empty arrays in transform spread (#6763)
* No unneeded empty arrays in transform spread Since Array.prototype.concat creates a new array from inputs, there's no need to call it from a new empty array ([].concat()). * [fixup] simplify detection of new array
This commit is contained in:
committed by
Henry Zhu
parent
617d35245f
commit
aefbb1380e
@@ -21,7 +21,7 @@ var _ref4 = [a[1], a[0]];
|
||||
a[0] = _ref4[0];
|
||||
a[1] = _ref4[1];
|
||||
|
||||
var _ref5 = [].concat(babelHelpers.toConsumableArray(foo), [bar]),
|
||||
var _ref5 = babelHelpers.toConsumableArray(foo).concat([bar]),
|
||||
a = _ref5[0],
|
||||
b = _ref5[1];
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ var b = [...a, 'foo'];
|
||||
|
||||
```js
|
||||
var a = [ 'a', 'b', 'c' ];
|
||||
var b = [].concat(a, [ 'foo' ]);
|
||||
var b = a.concat([ 'foo' ]);
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -52,11 +52,11 @@ export default function(api, options) {
|
||||
if (!hasSpread(elements)) return;
|
||||
|
||||
const nodes = build(elements, scope, state);
|
||||
let first = nodes.shift();
|
||||
const first = nodes.shift();
|
||||
|
||||
if (!t.isArrayExpression(first)) {
|
||||
nodes.unshift(first);
|
||||
first = t.arrayExpression([]);
|
||||
if (nodes.length === 0 && first !== elements[0].argument) {
|
||||
path.replaceWith(first);
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function foo() {
|
||||
return bar([].concat(Array.prototype.slice.call(arguments)));
|
||||
return bar(Array.prototype.slice.call(arguments));
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
var lyrics = [].concat(babelHelpers.toConsumableArray(parts), ["head", "and", "toes"]);
|
||||
var lyrics = babelHelpers.toConsumableArray(parts).concat(["head", "and", "toes"]);
|
||||
|
||||
@@ -3,5 +3,5 @@ function foo() {
|
||||
bar[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return [].concat(bar);
|
||||
return bar.concat();
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
[].concat(babelHelpers.toConsumableArray(foo));
|
||||
babelHelpers.toConsumableArray(foo);
|
||||
|
||||
Reference in New Issue
Block a user