Stage 2 decorators are in progress babel/babel#2645. Patches welcome!
In Babel 7, transform-decorators-legacy will be the default plugin in Stage-0.
(examples are from proposal)
@annotation
class MyClass { }
function annotation(target) {
target.annotated = true;
}
@isTestable(true)
class MyClass { }
function isTestable(value) {
return function decorator(target) {
target.isTestable = value;
}
}
class C {
@enumerable(false)
method() { }
}
function enumerable(value) {
return function (target, key, descriptor) {
descriptor.enumerable = value;
return descriptor;
}
}
npm install --save-dev babel-plugin-transform-decorators
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-decorators"]
}
babel --plugins transform-decorators script.js
require("babel-core").transform("code", {
plugins: ["transform-decorators"]
});