7.2.1-26 • Published 7 years ago

@gerhobbelt/babel-plugin-codemod-object-assign-to-object-spread v7.2.1-26

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@gerhobbelt/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 @gerhobbelt/babel-plugin-codemod-object-assign-to-object-spread

Usage

Via .babelrc (Recommended)

.babelrc

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

Via CLI

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

Via Node API

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