Skip to content

Commit

Permalink
Remove decoratorsBeforeExport from generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 25, 2022
1 parent e7290d9 commit b847696
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
12 changes: 8 additions & 4 deletions packages/babel-generator/src/generators/classes.ts
Expand Up @@ -11,11 +11,15 @@ export function ClassDeclaration(
node: t.ClassDeclaration,
parent: t.Node,
) {
if (
!this.format.decoratorsBeforeExport ||
(!isExportDefaultDeclaration(parent) && !isExportNamedDeclaration(parent))
) {
if (process.env.BABEL_8_BREAKING) {
this.printJoin(node.decorators, node);
} else {
if (
!this.format.decoratorsBeforeExport ||
(!isExportDefaultDeclaration(parent) && !isExportNamedDeclaration(parent))
) {
this.printJoin(node.decorators, node);
}
}

if (node.declare) {
Expand Down
24 changes: 14 additions & 10 deletions packages/babel-generator/src/generators/modules.ts
Expand Up @@ -90,11 +90,13 @@ export function ExportNamedDeclaration(
this: Printer,
node: t.ExportNamedDeclaration,
) {
if (
this.format.decoratorsBeforeExport &&
isClassDeclaration(node.declaration)
) {
this.printJoin(node.declaration.decorators, node);
if (!process.env.BABEL_8_BREAKING) {
if (
this.format.decoratorsBeforeExport &&
isClassDeclaration(node.declaration)
) {
this.printJoin(node.declaration.decorators, node);
}
}

this.word("export");
Expand Down Expand Up @@ -156,11 +158,13 @@ export function ExportDefaultDeclaration(
this: Printer,
node: t.ExportDefaultDeclaration,
) {
if (
this.format.decoratorsBeforeExport &&
isClassDeclaration(node.declaration)
) {
this.printJoin(node.declaration.decorators, node);
if (!process.env.BABEL_8_BREAKING) {
if (
this.format.decoratorsBeforeExport &&
isClassDeclaration(node.declaration)
) {
this.printJoin(node.declaration.decorators, node);
}
}

this.word("export");
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-generator/src/index.ts
Expand Up @@ -66,7 +66,6 @@ function normalizeOptions(
style: " ",
base: 0,
},
decoratorsBeforeExport: !!opts.decoratorsBeforeExport,
jsescOption: {
quotes: "double",
wrap: true,
Expand All @@ -78,6 +77,7 @@ function normalizeOptions(
};

if (!process.env.BABEL_8_BREAKING) {
format.decoratorsBeforeExport = !!opts.decoratorsBeforeExport;
format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
}

Expand Down Expand Up @@ -193,6 +193,7 @@ export interface GeneratorOptions {
/**
* Set to true to enable support for experimental decorators syntax before module exports.
* Defaults to `false`.
* @deprecated Removed in Babel 8
*/
decoratorsBeforeExport?: boolean;

Expand Down
5 changes: 4 additions & 1 deletion packages/babel-generator/src/printer.ts
Expand Up @@ -35,7 +35,6 @@ export type Format = {
style: string;
base: number;
};
decoratorsBeforeExport: boolean;
recordAndTupleSyntaxType: RecordAndTuplePluginOptions["syntaxType"];
jsescOption: jsescOptions;
jsonCompatibleStrings?: boolean;
Expand All @@ -44,6 +43,10 @@ export type Format = {
* Changes what token is used for pipe bodies’ topic references.
*/
topicToken?: PipelineOperatorPluginOptions["topicToken"];
/**
* @deprecated Removed in Babel 8
*/
decoratorsBeforeExport?: boolean;
};

interface AddNewlinesOptions {
Expand Down
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": false,
"plugins": [["decorators", { "decoratorsBeforeExport": false }]],
"decoratorsBeforeExport": false
}
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": false,
"plugins": [["decorators", { "decoratorsBeforeExport": false }]],
"decoratorsBeforeExport": true
}
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": false,
"plugins": [["decorators", { "decoratorsBeforeExport": true }]],
"decoratorsBeforeExport": false
}
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": false,
"plugins": [["decorators", { "decoratorsBeforeExport": true }]],
"decoratorsBeforeExport": true
}
10 changes: 1 addition & 9 deletions packages/babel-standalone/test/preset-stage-1.test.js
Expand Up @@ -50,15 +50,7 @@ const require = createRequire(import.meta.url);
it("should support decorators versioned 2021-12", () => {
const output = Babel.transform("@dec class C {}", {
plugins: [["external-helpers", { helperVersion: "7.100.0" }]],
presets: [
[
"stage-1",
{
decoratorsVersion: "2021-12",
decoratorsBeforeExport: false,
},
],
],
presets: [["stage-1", { decoratorsVersion: "2021-12" }]],
}).code;
expect(output).toMatch("babelHelpers.applyDecs");
});
Expand Down

0 comments on commit b847696

Please sign in to comment.