babel-plugin-syntax-decorators
Installation
npm install --save-dev @babel/plugin-syntax-decorators
Usage
.babelrc
(Recommended)
Via .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 false
.
// 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