@babel/plugin-syntax-decorators
Syntax only
It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use plugin-proposal-decorators to both parse and transform this syntax.
Installation
npm install --save-dev @babel/plugin-syntax-decorators
Usage
With a configuration file (Recommended)
{
"plugins": ["@babel/plugin-syntax-decorators"]
}
Via CLI
babel --plugins @babel/plugin-syntax-decorators script.js
Via Node API
require("@babel/core").transformSync("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
You can read more about configuring plugin options here