跳到主要内容

@babel/plugin-transform-shorthand-properties

信息

This plugin is included in @babel/preset-env

Example

In

JavaScript
var o = { a, b, c };

Out

JavaScript
var o = { a: a, b: b, c: c };

In

JavaScript
var cat = {
getName() {
return name;
},
};

Out

JavaScript
var cat = {
getName: function() {
return name;
},
};

Installation

npm install --save-dev @babel/plugin-transform-shorthand-properties

Usage

babel.config.json
{
"plugins": ["@babel/plugin-transform-shorthand-properties"]
}

Via CLI

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

Via Node API

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