UNPKG

875 BMarkdownView Raw
1# @babel/plugin-codemod-object-assign-to-object-spread
2
3Transforms old code that uses `Object.assign` with an Object Literal as
4the first param to use Object Spread syntax.
5
6## Examples
7
8```js
9const obj = Object.assign({
10 test1: 1,
11}, other, {
12 test2: 2,
13}, other2);
14```
15
16Is transformed to:
17
18```js
19const obj = {
20 test1: 1,
21 ...other,
22 test2: 2,
23 ...other2,
24};
25```
26
27## Installation
28
29```sh
30npm install --save-dev @babel/plugin-codemod-object-assign-to-object-spread
31```
32
33## Usage
34
35### Via `.babelrc` (Recommended)
36
37**.babelrc**
38
39```jsonc
40{
41 "plugins": ["@babel/plugin-codemod-object-assign-to-object-spread"]
42}
43```
44
45### Via CLI
46
47```sh
48babel --plugins @babel/plugin-codemod-object-assign-to-object-spread script.js
49```
50
51### Via Node API
52
53```javascript
54require("@babel/core").transform("code", {
55 plugins: ["@babel/plugin-codemod-object-assign-to-object-spread"]
56});
57```