package
This plugin transforms static class properties as well as properties declared with the property initializer syntax
npm install babel-plugin-transform-class-propertiesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
This plugin transforms es2015 static class properties as well as properties declared with the es2016 property initializer syntax.
Below is a class with four class properties which will be transformed.
class Bork {
//Property initializer syntax
instanceProperty = "bork";
boundFunction = () => {
return this.instanceProperty;
}
//Static class properties
static staticProperty = "babelIsCool";
static staticFunction = function() {
return Bork.staticProperty;
}
}
let myBork = new Bork;
//Property initializers are not on the prototype.
console.log(myBork.prototype.boundFunction); // > undefined
//Bound functions are bound to the class instance.
console.log(myBork.boundFunction.call(undefined)); // > "bork"
//Static function exists on the class.
console.log(Bork.staticFunction()); // > "babelIsCool"npm install --save-dev babel-plugin-transform-class-properties.babelrc (Recommended).babelrc
// without options
{
"plugins": ["transform-class-properties"]
}
// with options
{
"plugins": [
["transform-class-properties", { "spec": true }]
]
}babel --plugins transform-class-properties script.jsrequire("babel-core").transform("code", {
plugins: ["transform-class-properties"]
});specboolean, defaults to false.
Class properties are compiled to use Object.defineProperty. Static fields are now defined even if they are not initialized.
Estimated unpacked size across 19 packages.
3.0 MB
Includes dependencies.
4 direct dependencies.
Latest published Apr 7, 2017
next
loganfsmyth
loganfsmyth@gmail.com