Compile let decorators to ES6
(get more examples from proposal)
@annotation
let a = {};
function annotation(target) {
target.annotated = true;
}
@logger(true)
let a = () => {};
function logger(flag) {
return function(target) {
if (flag) {
return (...x) => (result => (console.log(result), result))(target(...x));
} else {
return target;
}
};
}
@double
@inc
let a = 0;
function inc(value) {
return value + 1;
}
function double(value) {
return value * 2;
};
npm install --save-dev github:ukari/babel-plugin-syntax-let-decorators
Add the following line to your .babelrc file:
{
"plugins": ["@babel/plugin-proposal-let-decorators"]
}
babel --plugins @babel/plugin-proposal-let-decorators script.js
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-proposal-let-decorators"]
});