11b0a19cb8b19d695492be416e9c6a9177cfe22349b5bebf94bfcf1af631c163de1b8712ed78b0b95ec6f192f1e4e383686517a3617d7259a18b0e31ba3131 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # babel-plugin-transform-es2015-duplicate-keys
  2. > Compile objects with duplicate keys to valid strict ES5.
  3. This plugin actually converts duplicate keys in objects to be computed properties, which then must be handled by the [transform-es2015-computed-properties](http://babeljs.io/docs/plugins/transform-es2015-computed-properties) plugin. The final result won't contain any object literals with duplicate keys.
  4. ## Example
  5. **In**
  6. ```javascript
  7. var x = { a: 5, a: 6 };
  8. var y = {
  9. get a() {},
  10. set a(x) {},
  11. a: 3
  12. };
  13. ```
  14. **Out**
  15. ```javascript
  16. var x = { a: 5, ["a"]: 6 };
  17. var y = {
  18. get a() {},
  19. set a(x) {},
  20. ["a"]: 3
  21. };
  22. ```
  23. ## Installation
  24. ```sh
  25. npm install --save-dev babel-plugin-transform-es2015-duplicate-keys
  26. ```
  27. ## Usage
  28. ### Via `.babelrc` (Recommended)
  29. **.babelrc**
  30. ```json
  31. {
  32. "plugins": ["transform-es2015-duplicate-keys"]
  33. }
  34. ```
  35. ### Via CLI
  36. ```sh
  37. babel --plugins transform-es2015-duplicate-keys script.js
  38. ```
  39. ### Via Node API
  40. ```javascript
  41. require("babel-core").transform("code", {
  42. plugins: ["transform-es2015-duplicate-keys"]
  43. });
  44. ```