Use printBlock to print ClassBody (#9915)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-12-21 17:10:03 +08:00
1 parent f0f18d3090
commit be497c3c8f
5 files changed
+6 -28

No files matched your search

+2 -1
View File
@@ -41,7 +41,8 @@ function printBlock(path, options, print) {
(parent.type === "CatchClause" && !parentParent.finalizer) ||
parent.type === "TSModuleDeclaration" ||
parent.type === "TSDeclareFunction" ||
node.type === "StaticBlock"
node.type === "StaticBlock" ||
node.type === "ClassBody"
)
) {
parts.push(hardline);
-18
View File
@@ -13,7 +13,6 @@ const {
const { getTypeParametersGroupId } = require("./type-parameters");
const { printMethod } = require("./function");
const { printOptionalToken, printTypeAnnotation } = require("./misc");
const { printBody } = require("./statement");
const { printPropertyKey } = require("./property");
const { printAssignmentRight } = require("./assignment");
@@ -177,22 +176,6 @@ function printClassMethod(path, options, print) {
return concat(parts);
}
function printClassBody(path, options, print) {
const n = path.getValue();
if (!hasComment(n) && n.body.length === 0) {
return "{}";
}
return concat([
"{",
n.body.length > 0
? indent(concat([hardline, printBody(path, options, print)]))
: printDanglingComments(path, options),
hardline,
"}",
]);
}
function printClassProperty(path, options, print) {
const n = path.getValue();
const parts = [];
@@ -249,6 +232,5 @@ function printDecorators(path, options, print) {
module.exports = {
printClass,
printClassMethod,
printClassBody,
printClassProperty,
};
+1 -3
View File
@@ -80,7 +80,6 @@ const { printObject } = require("./print/object");
const {
printClass,
printClassMethod,
printClassBody,
printClassProperty,
} = require("./print/class");
const { printTypeParameters } = require("./print/type-parameters");
@@ -424,6 +423,7 @@ function printPathNoParens(path, options, print, args) {
return "import";
case "BlockStatement":
case "StaticBlock":
case "ClassBody":
return printBlock(path, options, print);
case "ThrowStatement":
return printThrowStatement(path, options, print);
@@ -901,8 +901,6 @@ function printPathNoParens(path, options, print, args) {
case "ClassDeclaration":
case "ClassExpression":
return printClass(path, options, print);
case "ClassBody":
return printClassBody(path, options, print);
case "ClassMethod":
case "ClassPrivateMethod":
case "MethodDefinition":
@@ -118,8 +118,7 @@ class A1 extends B {
}
class A2 /* a */ extends B {}
class A3 extends B /* a */ {
}
class A3 extends B /* a */ {}
class A4 /* a */ extends B {}
(class A5 // comment 1
@@ -133,8 +132,7 @@ class A4 /* a */ extends B {}
});
(class A7 /* a */ extends B {});
(class A8 extends B /* a */ {
});
(class A8 extends B /* a */ {});
(class A9 /* a */ extends B {});
class a extends b {
@@ -28,8 +28,7 @@ import React from "react";
/*:: type State = { baz: number }; */
class Component extends React.Component /*:: <Props, State> */ {
}
class Component extends React.Component /*:: <Props, State> */ {}
================================================================================
`;