@babel/plugin-codemod-object-assign-to-object-spread

7.10.4 • Public • Published

@babel/plugin-codemod-object-assign-to-object-spread

Transforms old code that uses Object.assign with an Object Literal as the first param to use Object Spread syntax.

Examples

const obj = Object.assign({
  test1: 1,
}, other, {
  test2: 2,
}, other2);

Is transformed to:

const obj = {
  test1: 1,
  ...other,
  test2: 2,
  ...other2,
};

Installation

npm install --save-dev @babel/plugin-codemod-object-assign-to-object-spread

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["@babel/plugin-codemod-object-assign-to-object-spread"]
}

Via CLI

babel --plugins @babel/plugin-codemod-object-assign-to-object-spread script.js

Via Node API

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

/@babel/plugin-codemod-object-assign-to-object-spread/

    Package Sidebar

    Install

    npm i @babel/plugin-codemod-object-assign-to-object-spread

    Weekly Downloads

    228

    Version

    7.10.4

    License

    MIT

    Unpacked Size

    3.94 kB

    Total Files

    4

    Last publish

    Collaborators

    • hzoo
    • existentialism
    • nicolo-ribaudo
    • jlhwung