ES2015 shorthand properties transform

Compile ES2015 shorthand properties and methods to ES5

示例

输入

var o = { a, b, c };

输出

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

输入

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

输出

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

安装

npm install --save-dev babel-plugin-transform-es2015-shorthand-properties

用法

通过 .babelrc(推荐)

.babelrc

{
  "plugins": ["transform-es2015-shorthand-properties"]
}

通过 CLI

babel --plugins transform-es2015-shorthand-properties script.js

通过 Node API

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