@babel/plugin-transform-duplicate-keys

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").transform("code", {
  2. plugins: ["@babel/plugin-transform-duplicate-keys"],
  3. });