1 | # babel-plugin-transform-es2015-duplicate-keys
|
2 |
|
3 | > Compile objects with duplicate keys to valid strict ES5.
|
4 |
|
5 | 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.
|
6 |
|
7 | ## Example
|
8 |
|
9 | **In**
|
10 |
|
11 | ```javascript
|
12 | var x = { a: 5, a: 6 };
|
13 | var y = {
|
14 | get a() {},
|
15 | set a(x) {},
|
16 | a: 3
|
17 | };
|
18 | ```
|
19 |
|
20 | **Out**
|
21 |
|
22 | ```javascript
|
23 | var x = { a: 5, ["a"]: 6 };
|
24 | var y = {
|
25 | get a() {},
|
26 | set a(x) {},
|
27 | ["a"]: 3
|
28 | };
|
29 | ```
|
30 |
|
31 | ## Installation
|
32 |
|
33 | ```sh
|
34 | npm install --save-dev babel-plugin-transform-es2015-duplicate-keys
|
35 | ```
|
36 |
|
37 | ## Usage
|
38 |
|
39 | ### Via `.babelrc` (Recommended)
|
40 |
|
41 | **.babelrc**
|
42 |
|
43 | ```json
|
44 | {
|
45 | "plugins": ["transform-es2015-duplicate-keys"]
|
46 | }
|
47 | ```
|
48 |
|
49 | ### Via CLI
|
50 |
|
51 | ```sh
|
52 | babel --plugins transform-es2015-duplicate-keys script.js
|
53 | ```
|
54 |
|
55 | ### Via Node API
|
56 |
|
57 | ```javascript
|
58 | require("babel-core").transform("code", {
|
59 | plugins: ["transform-es2015-duplicate-keys"]
|
60 | });
|
61 | ```
|