babel/codemods/babel-plugin-codemod-object-assign-to-object-spread
Justin Ridgewell 2afe9404fe
Use Object Spread Syntax (#7777)
* Use Object Spread Syntax

* Nits
2018-04-23 21:44:27 -04:00
..
2018-04-23 21:44:27 -04:00
2018-04-23 21:44:27 -04:00
2018-04-23 21:44:27 -04:00
2018-04-23 21:44:27 -04:00
2018-04-23 21:44:27 -04:00

@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

.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"]
});