From 2127df0db0cb20eef69acb858e8259d0ff410dd6 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Thu, 2 Mar 2017 22:29:34 -0600 Subject: [PATCH] Fix transform-object-rest-spread README [skip ci] (#5409) --- .../README.md | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/packages/babel-plugin-transform-object-rest-spread/README.md b/packages/babel-plugin-transform-object-rest-spread/README.md index 61c3debfff..79f2432d03 100644 --- a/packages/babel-plugin-transform-object-rest-spread/README.md +++ b/packages/babel-plugin-transform-object-rest-spread/README.md @@ -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)