Add "decoratorsBeforeExport" option to @babel/generator (#7948)

* Add "decoratorsBeforeExport" option to @babel/generator

* Docs
This commit is contained in:
Nicolò Ribaudo
2018-05-27 08:50:26 +02:00
committed by GitHub
parent f699f1bbbf
commit d45ee5e025
18 changed files with 105 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ import legacyVisitor from "./transformer-legacy";
export default declare((api, options) => {
api.assertVersion(7);
const { legacy = false } = options;
const { legacy = false, decoratorsBeforeExport } = options;
if (typeof legacy !== "boolean") {
throw new Error("'legacy' must be a boolean.");
}
@@ -19,9 +19,24 @@ export default declare((api, 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.");
}
}
return {
inherits: syntaxDecorators,
manipulateOptions({ generatorOpts }) {
generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
},
visitor: legacy ? legacyVisitor : visitor,
};
});