web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.4 KiB

  1. # babel-plugin-transform-object-rest-spread
  2. > This plugin allows Babel to transform rest properties for object destructuring assignment and spread properties for object literals.
  3. ## Example
  4. ### Rest Properties
  5. ```js
  6. let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
  7. console.log(x); // 1
  8. console.log(y); // 2
  9. console.log(z); // { a: 3, b: 4 }
  10. ```
  11. ### Spread Properties
  12. ```js
  13. let n = { x, y, ...z };
  14. console.log(n); // { x: 1, y: 2, a: 3, b: 4 }
  15. ```
  16. ## Installation
  17. ```sh
  18. npm install --save-dev babel-plugin-transform-object-rest-spread
  19. ```
  20. ## Usage
  21. ### Via `.babelrc` (Recommended)
  22. **.babelrc**
  23. ```json
  24. {
  25. "plugins": ["transform-object-rest-spread"]
  26. }
  27. ```
  28. ### Via CLI
  29. ```sh
  30. babel --plugins transform-object-rest-spread script.js
  31. ```
  32. ### Via Node API
  33. ```javascript
  34. require("babel-core").transform("code", {
  35. plugins: ["transform-object-rest-spread"]
  36. });
  37. ```
  38. ## Options
  39. ### `useBuiltIns`
  40. `boolean`, defaults to `false`.
  41. By default, this plugin uses Babel's `extends` helper which polyfills `Object.assign`. Enabling this option will use `Object.assign` directly.
  42. **.babelrc**
  43. ```json
  44. {
  45. "plugins": [
  46. ["transform-object-rest-spread", { "useBuiltIns": true }]
  47. ]
  48. }
  49. ```
  50. **In**
  51. ```js
  52. z = { x, ...y };
  53. ```
  54. **Out**
  55. ```js
  56. z = Object.assign({ x }, y);
  57. ```
  58. ## References
  59. * [Proposal: Object Rest/Spread Properties for ECMAScript](https://github.com/sebmarkbage/ecmascript-rest-spread)
  60. * [Spec](http://sebmarkbage.github.io/ecmascript-rest-spread)