@babel/plugin-transform-spread

    In

    Out

    1. var a = ["a", "b", "c"];
    2. var c = foo.apply(void 0, a);
    1. npm install --save-dev @babel/plugin-transform-spread

    Without options:

    With options:

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

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

    1. // babel.config.json
    2. {
    3. "assumptions": {
    4. "iterableIsArray": true
    5. }
    6. }

    Under the iterableIsArray assumption, Babel preserves “holes” when spreading an array (for example, [ ...Array(2) ] produces [ (hole), (hole) ]). Set iterableIsArray to false to avoid this behaviour.

    Added in: v7.10.0

    This option allows spreading array-like objects as if they were arrays.

    1. // babel.config.json
    2. {
    3. "assumptions": {
    4. "arrayLikeIsIterable": true
    5. }

    An array-like object is an object with a length property: for example, { 0: "a", 1: "b", length: 2 }. Note that, like real arrays, array-like objects can have “holes”: { 1: "a", length: 3 } is equivalent to [ (hole), "a", (hole) ].

    Please note that Babel allows spreading arguments in old engines even if this option is disabled, because it’s defined as iterable in the ECMAScript specification.