Remove unnecessary parts (#18027)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-10-10 15:52:40 +08:00
1 parent 274b249223
commit a8c033a493
5 files changed
+20 -30

No files matched your search

+10 -14
View File
@@ -84,11 +84,8 @@ function isDeclareHookTypeAnnotation(path) {
*/
function printHookTypeAnnotation(path, options, print) {
const { node } = path;
const parts = [];
parts.push(isDeclareHookTypeAnnotation(path) ? "" : "hook ");
let parametersDoc = printFunctionParameters(
const parametersDoc = printFunctionParameters(
path,
options,
print,
@@ -96,19 +93,18 @@ function printHookTypeAnnotation(path, options, print) {
/* printTypeParams */ true,
);
const returnTypeDoc = [];
returnTypeDoc.push(
const returnTypeDoc = [
isDeclareHookTypeAnnotation(path) ? ": " : " => ",
print("returnType"),
);
];
if (shouldGroupFunctionParameters(node, returnTypeDoc)) {
parametersDoc = group(parametersDoc);
}
parts.push(parametersDoc, returnTypeDoc);
return group(parts);
return group([
isDeclareHookTypeAnnotation(path) ? "" : "hook ",
shouldGroupFunctionParameters(node, returnTypeDoc)
? group(parametersDoc)
: parametersDoc,
returnTypeDoc,
]);
}
export { printDeclareHook, printHook, printHookTypeAnnotation };
+1 -2
View File
@@ -546,8 +546,7 @@ function shouldBreakJsxElement(path) {
function printJsxAttribute(path, options, print) {
const { node } = path;
const parts = [];
parts.push(print("name"));
const parts = [print("name")];
if (node.value) {
let res;
+5 -8
View File
@@ -148,14 +148,11 @@ function printModuleSource(path, options, print) {
return "";
}
/** @type{Doc[]} */
const parts = [];
if (shouldPrintSpecifiers(node, options)) {
parts.push(" from");
}
parts.push(" ", print("source"));
return parts;
return [
shouldPrintSpecifiers(node, options) ? " from" : "",
" ",
print("source"),
];
}
function printModuleSpecifiers(path, options, print) {
+2 -4
View File
@@ -177,7 +177,6 @@ function printJestEachTemplateLiteral(path, options, print) {
options.__inJestEach = true;
const expressions = path.map(print, "expressions");
options.__inJestEach = false;
const parts = [];
const stringifiedExpressions = expressions.map(
(doc) =>
"${" +
@@ -223,7 +222,7 @@ function printJestEachTemplateLiteral(path, options, print) {
}
}
parts.push(
return [
lineSuffixBoundary,
"`",
indent([
@@ -245,8 +244,7 @@ function printJestEachTemplateLiteral(path, options, print) {
]),
hardline,
"`",
);
return parts;
];
}
}
+2 -2
View File
@@ -71,8 +71,6 @@ function printTypescript(path, options, print) {
return node.type.slice(2, -7).toLowerCase();
}
const parts = [];
switch (node.type) {
case "TSThisType":
return "this";
@@ -223,6 +221,7 @@ function printTypescript(path, options, print) {
return printTypeScriptMappedType(path, options, print);
case "TSMethodSignature": {
const parts = [];
const kind = node.kind && node.kind !== "method" ? `${node.kind} ` : "";
parts.push(
printTypeScriptAccessibilityToken(node),
@@ -281,6 +280,7 @@ function printTypescript(path, options, print) {
case "TSExternalModuleReference":
return ["require(", print("expression"), ")"];
case "TSModuleDeclaration": {
const parts = [];
const { parent } = path;
const parentIsDeclaration = parent.type === "TSModuleDeclaration";
const bodyIsDeclaration = node.body?.type === "TSModuleDeclaration";