Fix transform-object-rest-spread README [skip ci] (#5409)
This commit is contained in:
parent
0d3a7e9cc6
commit
2127df0db0
@ -4,19 +4,22 @@
|
||||
|
||||
## Example
|
||||
|
||||
### Rest Properties
|
||||
|
||||
```js
|
||||
// Rest properties
|
||||
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
|
||||
console.log(x); // 1
|
||||
console.log(y); // 2
|
||||
console.log(z); // { a: 3, b: 4 }
|
||||
```
|
||||
|
||||
// Spread properties
|
||||
### Spread Properties
|
||||
|
||||
```js
|
||||
let n = { x, y, ...z };
|
||||
console.log(n); // { x: 1, y: 2, a: 3, b: 4 }
|
||||
```
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
@ -35,27 +38,6 @@ npm install --save-dev babel-plugin-transform-object-rest-spread
|
||||
}
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
This plugin will use babel's `extends` helper, which will polyfill `Object.assign` by default.
|
||||
|
||||
* `useBuiltIns` - Do not use Babel's helper's and just transform to use the built-in method (Disabled by default).
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
["transform-object-rest-spread", { "useBuiltIns": true }]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
// source
|
||||
z = { x, ...y };
|
||||
// compiled
|
||||
z = Object.assign({ x }, y);
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
@ -70,6 +52,36 @@ require("babel-core").transform("code", {
|
||||
});
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### `useBuiltIns`
|
||||
|
||||
`boolean`, defaults to `false`.
|
||||
|
||||
By default, this plugin uses Babel's `extends` helper which polyfills `Object.assign`. Enabling this option will use `Object.assign` directly.
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
["transform-object-rest-spread", { "useBuiltIns": true }]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```js
|
||||
z = { x, ...y };
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```js
|
||||
z = Object.assign({ x }, y);
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [Proposal: Object Rest/Spread Properties for ECMAScript](https://github.com/sebmarkbage/ecmascript-rest-spread)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user