@babel/plugin-transform-duplicate-keys

NOTE: This plugin is included in @babel/preset-env

This plugin actually converts duplicate keys in objects to be computed properties, which then must be handled by the @babel/plugin-transform-computed-properties plugin. The final result won’t contain any object literals with duplicate keys.

Example

In

  1. var x = { a: 5, a: 6 };
  2. var y = {
  3. get a() {},
  4. set a(x) {},
  5. a: 3,
  6. };

Out

  1. var x = { a: 5, ["a"]: 6 };
  2. var y = {
  3. get a() {},
  4. set a(x) {},
  5. ["a"]: 3,
  6. };

Installation

  1. npm install --save-dev @babel/plugin-transform-duplicate-keys

Usage

  1. {
  2. "plugins": ["@babel/plugin-transform-duplicate-keys"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-transform-duplicate-keys script.js

Via Node API

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-transform-duplicate-keys"],
  3. });