Anatoli Papirovski aefbb1380e 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
2017-11-09 14:51:56 -05:00

863 B

@babel/plugin-transform-spread

Compile ES2015 spread to ES5

Example

In

var a = ['a', 'b', 'c'];
var b = [...a, 'foo'];

Out

var a = [ 'a', 'b', 'c' ];
var b = a.concat([ 'foo' ]);

Installation

npm install --save-dev @babel/plugin-transform-spread

Usage

.babelrc

Without options:

{
  "plugins": ["@babel/transform-spread"]
}

With options:

{
  "plugins": [
    ["@babel/transform-spread", {
      "loose": true
    }]
  ]
}

Via CLI

babel --plugins @babel/transform-spread script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/transform-spread"]
});

Options

loose

boolean, defaults to false.

In loose mode, all iterables are assumed to be arrays.