@babel/plugin-transform-shorthand-properties

shorthand-properties - 图1info

This plugin is included in @babel/preset-env

Example

In

JavaScript

  1. var o = { a, b, c };

Out

JavaScript

  1. var o = { a: a, b: b, c: c };

In

JavaScript

  1. var cat = {
  2. getName() {
  3. return name;
  4. },
  5. };

Out

JavaScript

  1. var cat = {
  2. getName: function() {
  3. return name;
  4. },
  5. };

Installation

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

Usage

babel.config.json

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

Via CLI

Shell

  1. babel --plugins @babel/plugin-transform-shorthand-properties script.js

Via Node API

JavaScript

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