Update syntax-decorators options (#7938)

* Add decoratorsBeforeExport to the syntax plugin
* Require legacy: true, like in the transform plugin
This commit is contained in:
Nicolò Ribaudo
2018-05-30 22:00:18 +02:00
committed by GitHub
parent 21b9b2e42d
commit cb17f07ac9
7 changed files with 135 additions and 5 deletions

View File

@@ -8,9 +8,35 @@ export default declare((api, options) => {
throw new Error("'legacy' must be a boolean.");
}
if (legacy !== true) {
throw new Error(
"The new decorators proposal is not supported yet." +
' You must pass the `"legacy": true` option to' +
" @babel/plugin-syntax-decorators",
);
}
let { decoratorsBeforeExport } = options;
if (decoratorsBeforeExport !== undefined) {
if (legacy) {
throw new Error(
"'decoratorsBeforeExport' can't be used with legacy decorators.",
);
}
if (typeof decoratorsBeforeExport !== "boolean") {
throw new Error("'decoratorsBeforeExport' must be a boolean.");
}
} else if (!legacy) {
decoratorsBeforeExport = true;
}
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push(legacy ? "decorators-legacy" : "decorators");
parserOpts.plugins.push(
legacy
? "decorators-legacy"
: ["decorators", { decoratorsBeforeExport }],
);
},
};
});