@babel/plugin-proposal-object-rest-spread

    Spread Properties

    1. let n = { x, y, ...z };
    2. console.log(n); // { x: 1, y: 2, a: 3, b: 4 }
    1. npm install --save-dev @babel/plugin-proposal-object-rest-spread

    Via CLI

    1. babel --plugins @babel/plugin-proposal-object-rest-spread script.js
    1. require("@babel/core").transformSync("code", {
    2. plugins: ["@babel/plugin-proposal-object-rest-spread"],
    3. });

    By default, this plugin will produce spec compliant code by using Babel’s objectSpread helper.

    boolean, defaults to false.

    Enabling this option will use Babel’s extends helper, which is basically the same as Object.assign (see useBuiltIns below to use it directly).

    Please keep in mind that even if they’re almost equivalent, there’s an important difference between spread and Object.assign: spread defines new properties, while Object.assign() sets them, so using this mode might produce unexpected results in some cases.

    For detailed information please check out Spread VS. Object.assign and .

    boolean, defaults to false.

    Example

    .babelrc

    1. {
    2. "setSpreadProperties": true
    3. },
    4. "plugins": [
    5. ["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }]
    6. ]
    7. }

    In

    1. z = { x, ...y };

    Out