Compile class and object decorators to ES5
> Compile class and object decorators to ES5
(examples are from proposal)
``js
@annotation
class MyClass { }
function annotation(target) {
target.annotated = true;
}
`
`js
@isTestable(true)
class MyClass { }
function isTestable(value) {
return function decorator(target) {
target.isTestable = value;
}
}
`
`js
class C {
@enumerable(false)
method() { }
}
function enumerable(value) {
return function (target, key, descriptor) {
descriptor.enumerable = value;
return descriptor;
}
}
`
`sh`
npm install --save-dev babel-plugin-transform-decorators
.babelrc
`json`
{
"plugins": ["transform-decorators"]
}
`sh`
babel --plugins transform-decorators script.js
`javascript``
require("babel-core").transform("code", {
plugins: ["transform-decorators"]
});