* Add decoratorsBeforeExport to the syntax plugin * Require legacy: true, like in the transform plugin
@babel/plugin-syntax-decorators
Allow parsing of decorators.
Installation
npm install --save-dev @babel/plugin-syntax-decorators
Usage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["@babel/plugin-syntax-decorators"]
}
Via CLI
babel --plugins @babel/plugin-syntax-decorators script.js
Via Node API
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-syntax-decorators"]
});
Options
legacy
boolean, defaults to false.
Use the legacy (stage 1) decorators syntax.
decoratorsBeforeExport
boolean, defaults to true.
// decoratorsBeforeExport: true
@decorator
export class Foo {}
// decoratorsBeforeExport: false
export @decorator class Bar {}
This option was added to help tc39 collect feedback from the community by allowing experimentation with both possible syntaxes.
For more information, check out: tc39/proposal-decorators#69