Socket
Socket
Sign inDemoInstall

babel-plugin-transform-es2015-duplicate-keys

Package Overview
Dependencies
7
Maintainers
6
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-es2015-duplicate-keys

Compile objects with duplicate keys to valid strict ES5


Version published
Weekly downloads
1.4M
increased by1.53%
Maintainers
6
Install size
3.76 MB
Created
Weekly downloads
 

Package description

What is babel-plugin-transform-es2015-duplicate-keys?

The babel-plugin-transform-es2015-duplicate-keys npm package is designed to transform duplicate keys in object literals to valid ES2015 (also known as ES6) syntax. This is particularly useful when you are working with code that needs to be compatible with ES2015 standards, as duplicate keys in object literals were handled differently in ES5 and earlier versions. This plugin ensures that your code adheres to the latest standards, avoiding potential issues in environments that strictly follow ES2015+ specifications.

What are babel-plugin-transform-es2015-duplicate-keys's main functionalities?

Transforming Duplicate Keys

This feature automatically transforms objects with duplicate keys in your JavaScript code. For example, if you have an object literal with two 'foo' keys, each with different types or values, this plugin will help ensure that the object is transformed in a way that is compatible with ES2015 standards. The exact transformation depends on the plugin's implementation details and the JavaScript engine's handling of such cases.

{"type": "object", "properties": {"foo": {"type": "number"}, "foo": {"type": "string"}}}

Other packages similar to babel-plugin-transform-es2015-duplicate-keys

Readme

Source

babel-plugin-transform-es2015-duplicate-keys

Compile objects with duplicate keys to valid strict ES5.

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

Example

In

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

Out

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

Installation

npm install --save-dev babel-plugin-transform-es2015-duplicate-keys

Usage

.babelrc

{
  "plugins": ["transform-es2015-duplicate-keys"]
}

Via CLI

babel --plugins transform-es2015-duplicate-keys script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-es2015-duplicate-keys"]
});

Keywords

FAQs

Last updated on 07 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc