作用:用来编译类(class)
安装:npm install --save-dev @babel/plugin-proposal-class-properties
配置:.babelrc
有参数:{ "plugins": [ ["@babel/plugin-proposal-class-properties", { "loose": true }] ] }
没参数:{ "plugins": ["@babel/plugin-proposal-class-properties"] }
有参数和没参数编译行为不同:
class Bork {
static a = 'foo';
static b;
x = 'bar';
y;
}
没参数编译结果(默认{loose:false}):
var Bork = function Bork() { babelHelpers.classCallCheck(this, Bork); Object.defineProperty(this, "x", { configurable: true, enumerable: true, writable: true, value: 'bar' }); Object.defineProperty(this, "y", { configurable: true, enumerable: true, writable: true, value: void 0 }); }; Object.defineProperty(Bork, "a", { configurable: true, enumerable: true, writable: true, value: 'foo' }); Object.defineProperty(Bork, "b", { configurable: true, enumerable: true, writable: true, value: void 0 });
有参数编译结果:
var Bork = function Bork() { babelHelpers.classCallCheck(this, Bork); this.x = 'bar'; this.y = void 0; }; Bork.a = 'foo'; Bork.b = void 0;