Require decoratorsBeforeExport option for decorators (#8465)

* Require decoratorsBeforeExport option for syntax-decorators

* Also babylon

* Enable test
This commit is contained in:
Nicolò Ribaudo
2018-08-15 09:04:52 +02:00
committed by GitHub
parent 1e0b649485
commit d79b5eeeff
14 changed files with 111 additions and 24 deletions

View File

@@ -17,7 +17,14 @@ export default declare((api, options) => {
}
const { decoratorsBeforeExport } = options;
if (decoratorsBeforeExport !== undefined) {
if (decoratorsBeforeExport === undefined) {
if (!legacy) {
throw new Error(
"The '@babel/plugin-syntax-decorators' plugin requires a" +
" 'decoratorsBeforeExport' option, whose value must be a boolean.",
);
}
} else {
if (legacy) {
throw new Error(
"'decoratorsBeforeExport' can't be used with legacy decorators.",

View File

@@ -37,6 +37,10 @@ describe("'decoratorsBeforeExport' option", function() {
expect(makeParser("", { decoratorsBeforeExport: "before" })).toThrow();
});
test.skip("is required", function() {
expect(makeParser("", { legacy: false })).toThrow(/decoratorsBeforeExport/);
});
test("is incompatible with legacy", function() {
expect(
makeParser("", { decoratorsBeforeExport: false, legacy: true }),
@@ -47,8 +51,6 @@ describe("'decoratorsBeforeExport' option", function() {
const AFTER = "export @dec class Foo {}";
// These are skipped
run(BEFORE, undefined, true);
run(AFTER, undefined, false);
run(BEFORE, true, false);
run(AFTER, true, true);
run(BEFORE, false, true);