Add "decoratorsBeforeExport" option to @babel/generator (#7948)
* Add "decoratorsBeforeExport" option to @babel/generator * Docs
This commit is contained in:
@@ -2,8 +2,9 @@ import * as t from "@babel/types";
|
||||
|
||||
export function ClassDeclaration(node: Object, parent: Object) {
|
||||
if (
|
||||
!t.isExportDefaultDeclaration(parent) &&
|
||||
!t.isExportNamedDeclaration(parent)
|
||||
!this.format.decoratorsBeforeExport ||
|
||||
(!t.isExportDefaultDeclaration(parent) &&
|
||||
!t.isExportNamedDeclaration(parent))
|
||||
) {
|
||||
this.printJoin(node.decorators, node);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,10 @@ export function ExportAllDeclaration(node: Object) {
|
||||
}
|
||||
|
||||
export function ExportNamedDeclaration(node: Object) {
|
||||
if (t.isClassDeclaration(node.declaration)) {
|
||||
if (
|
||||
this.format.decoratorsBeforeExport &&
|
||||
t.isClassDeclaration(node.declaration)
|
||||
) {
|
||||
this.printJoin(node.declaration.decorators, node);
|
||||
}
|
||||
|
||||
@@ -67,7 +70,10 @@ export function ExportNamedDeclaration(node: Object) {
|
||||
}
|
||||
|
||||
export function ExportDefaultDeclaration(node: Object) {
|
||||
if (t.isClassDeclaration(node.declaration)) {
|
||||
if (
|
||||
this.format.decoratorsBeforeExport &&
|
||||
t.isClassDeclaration(node.declaration)
|
||||
) {
|
||||
this.printJoin(node.declaration.decorators, node);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,10 @@ function normalizeOptions(code, opts): Format {
|
||||
style: " ",
|
||||
base: 0,
|
||||
},
|
||||
decoratorsBeforeExport:
|
||||
opts.decoratorsBeforeExport === undefined
|
||||
? true
|
||||
: opts.decoratorsBeforeExport,
|
||||
};
|
||||
|
||||
if (format.minified) {
|
||||
|
||||
@@ -25,6 +25,7 @@ export type Format = {
|
||||
style: string,
|
||||
base: number,
|
||||
},
|
||||
decoratorsBeforeExport: boolean,
|
||||
};
|
||||
|
||||
export default class Printer {
|
||||
|
||||
Reference in New Issue
Block a user