@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
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-shorthand-properties
yarn add --dev @babel/plugin-transform-shorthand-properties
pnpm add --save-dev @babel/plugin-transform-shorthand-properties
Usage
With a configuration file (Recommended)
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"],
});