babel-plugin-transform-es2015-computed-properties
Compile ES2015 computed properties to ES5
Example
In
var obj = "x" + foo: "heh" "y" + bar: "noo" foo: "foo" bar: "bar";
Out
var _obj; { if key in obj Object; else objkey = value; return obj;} var obj = _obj = {} _obj;
Installation
npm install --save-dev babel-plugin-transform-es2015-computed-properties
Usage
.babelrc
(Recommended)
Via .babelrc
Without options:
With options:
Via CLI
babel --plugins transform-es2015-computed-properties script.js
Via Node API
;
Options
loose
boolean
, defaults to false
Just like method assignment in classes, in loose mode, computed property names use simple assignments instead of being defined. This is unlikely to be an issue in production code.
Example
In
var obj = "x" + foo: "heh" "y" + bar: "noo" foo: "foo" bar: "bar";
Out
var _obj; var obj = _obj = {} _obj"x" + foo = "heh" _obj"y" + bar = "noo" _objfoo = "foo" _objbar = "bar" _obj;