@babel/plugin-transform-property-literals

property-literals - 图1info

This plugin is included in @babel/preset-env

Example

In

JavaScript

  1. var foo = {
  2. // changed
  3. const: function() {},
  4. var: function() {},
  5. // not changed
  6. "default": 1,
  7. [a]: 2,
  8. foo: 1,
  9. };

Out

JavaScript

  1. var foo = {
  2. "const": function() {},
  3. "var": function() {},
  4. "default": 1,
  5. [a]: 2,
  6. foo: 1,
  7. };

Installation

  • npm
  • Yarn
  • pnpm
  1. npm install @babel/plugin-transform-property-literals --save-dev
  1. yarn add @babel/plugin-transform-property-literals --dev
  1. pnpm add @babel/plugin-transform-property-literals --save-dev

Usage

babel.config.json

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

Via CLI

Shell

  1. babel --plugins @babel/plugin-transform-property-literals script.js

Via Node API

JavaScript

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