Skip to content

Commit

Permalink
Also remove from @babel/generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 23, 2021
1 parent 5dcdd39 commit 35938c0
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 27 deletions.
9 changes: 6 additions & 3 deletions packages/babel-generator/src/generators/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ export function ClassDeclaration(
parent: any,
) {
if (
!this.format.decoratorsBeforeExport ||
(!t.isExportDefaultDeclaration(parent) &&
!t.isExportNamedDeclaration(parent))
!t.isExportDefaultDeclaration(parent) &&
!t.isExportNamedDeclaration(parent)
) {
this.printJoin(node.decorators, node);
} else if (!process.env.BABEL_8_BREAKING) {
if (!(this.format as any).decoratorsBeforeExport) {
this.printJoin(node.decorators, node);
}
}

if (node.declare) {
Expand Down
22 changes: 12 additions & 10 deletions packages/babel-generator/src/generators/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ export function ExportNamedDeclaration(
this: Printer,
node: t.ExportNamedDeclaration,
) {
if (
this.format.decoratorsBeforeExport &&
t.isClassDeclaration(node.declaration)
) {
this.printJoin(node.declaration.decorators, node);
if (t.isClassDeclaration(node.declaration)) {
if (process.env.BABEL_8_BREAKING) {
this.printJoin(node.declaration.decorators, node);
} else if ((this.format as any).decoratorsBeforeExport) {
this.printJoin(node.declaration.decorators, node);
}
}

this.word("export");
Expand All @@ -92,11 +93,12 @@ export function ExportDefaultDeclaration(
this: Printer,
node: t.ExportDefaultDeclaration,
) {
if (
this.format.decoratorsBeforeExport &&
t.isClassDeclaration(node.declaration)
) {
this.printJoin(node.declaration.decorators, node);
if (t.isClassDeclaration(node.declaration)) {
if (process.env.BABEL_8_BREAKING) {
this.printJoin(node.declaration.decorators, node);
} else if ((this.format as any).decoratorsBeforeExport) {
this.printJoin(node.declaration.decorators, node);
}
}

this.word("export");
Expand Down
8 changes: 1 addition & 7 deletions packages/babel-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function normalizeOptions(code, opts): Format {
style: " ",
base: 0,
},
decoratorsBeforeExport: !!opts.decoratorsBeforeExport,
jsescOption: {
quotes: "double",
wrap: true,
Expand All @@ -66,6 +65,7 @@ function normalizeOptions(code, opts): Format {

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

if (format.minified) {
Expand Down Expand Up @@ -176,12 +176,6 @@ export interface GeneratorOptions {
*/
jsonCompatibleStrings?: boolean;

/**
* Set to true to enable support for experimental decorators syntax before module exports.
* Defaults to `false`.
*/
decoratorsBeforeExport?: boolean;

/**
* Options for outputting jsesc representation.
*/
Expand Down
1 change: 0 additions & 1 deletion packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type Format = {
style: string;
base: number;
};
decoratorsBeforeExport: boolean;
recordAndTupleSyntaxType: "bar" | "hash";
jsescOption;
jsonCompatibleStrings?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": false,
"plugins": [
["decorators", { "decoratorsBeforeExport": false }],
"classProperties",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"BABEL_8_BREAKING": false
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"retainLines": true,
"plugins": [["decorators", { "decoratorsBeforeExport": true }]]
"plugins": ["decorators-legacy"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var obj = {
@foo
@bar
foo: "bar",

@foo
@bar
foo() {},

@foo
get foo() {},

@bar
set bar(foo) {}
};

class Foo {
@foo
@bar
foo() {}

@foo
@bar
foo() {}

@foo
get foo() {}

@bar
set bar(foo) {}
}

@foo
export default class Foo2 {
bar() {
class Baz {}
}
}

@foo
export class Foo3 {
bar() {
class Baz {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"BABEL_8_BREAKING": false,
"plugins": ["decorators-legacy"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var obj = {
@foo
@bar
foo: "bar",

@foo
@bar
foo() {},

@foo
get foo() {},

@bar
set bar(foo) {}

};

class Foo {
@foo
@bar
foo() {}

@foo
@bar
foo() {}

@foo
get foo() {}

@bar
set bar(foo) {}

}

export default @foo
class Foo2 {
bar() {
class Baz {}
}

}
export @foo
class Foo3 {
bar() {
class Baz {}
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ "plugins": ["decorators-legacy"] }
{
"BABEL_8_BREAKING": true,
"plugins": ["decorators-legacy"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class Foo {

}

export default @foo
class Foo2 {
@foo
export default class Foo2 {
bar() {
class Baz {}
}

}
export @foo
class Foo3 {
@foo
export class Foo3 {
bar() {
class Baz {}
}
Expand Down

0 comments on commit 35938c0

Please sign in to comment.