babel-plugin-transform-class-properties
This plugin transforms es2015 static class properties as well as properties declared with the es2016 property initializer syntax.
Example
Below is a class with four class properties which will be transformed.
//Property initializer syntax instanceProperty = "bork"; { return thisinstanceProperty; } //Static class properties static staticProperty = "babelIsCool"; static { return BorkstaticProperty; } let myBork = ; //Property initializers are not on the prototype. console; // > undefined //Bound functions are bound to the class instance. console; // > "bork" //Static function exists on the class. console; // > "babelIsCool"
Installation
npm install --save-dev babel-plugin-transform-class-properties
Usage
.babelrc
(Recommended)
Via .babelrc
// without options // with options
Via CLI
babel --plugins transform-class-properties script.js
Via Node API
;
Options
spec
boolean
, defaults to false
.
Class properties are compiled to use Object.defineProperty
. Static fields are now defined even if they are not initialized.