@babel/plugin-transform-spread

Example

In

  1. var a = ['a', 'b', 'c'];
  2. var b = [...a, 'foo'];
  3. var c = foo(...a);

Out

  1. var a = ['a', 'b', 'c'];
  2. var b = a.concat(['foo']);
  3. var c = foo.apply(void 0, a);

Installation

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

Usage

Without options:

  1. {
  2. "plugins": ["@babel/plugin-transform-spread"]
  3. }

With options:

  1. {
  2. "plugins": [
  3. ["@babel/plugin-transform-spread", {
  4. "loose": true
  5. }]
  6. ]
  7. }

Via CLI

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

Via Node API

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

Options

loose

boolean, defaults to false.

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

You can read more about configuring plugin options here

References