From fc70e992a78e0bb506ad2cd28b3e50359df66f06 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Oct 2025 22:55:25 +0800 Subject: [PATCH] Simplify `TSModuleDeclaration` print (#18116) --- src/language-js/print/typescript.js | 35 ++++++----------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 86697c074..e5beda621 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -278,34 +278,13 @@ function printTypescript(path, options, print) { ]; case "TSExternalModuleReference": return printCallExpression(path, options, print); - case "TSModuleDeclaration": { - const parts = []; - const { parent } = path; - const parentIsDeclaration = parent.type === "TSModuleDeclaration"; - const bodyIsDeclaration = node.body?.type === "TSModuleDeclaration"; - - if (parentIsDeclaration) { - parts.push("."); - } else { - parts.push(printDeclareToken(path)); - - if (node.kind !== "global") { - parts.push(node.kind, " "); - } - } - - parts.push(print("id")); - - if (bodyIsDeclaration) { - parts.push(print("body")); - } else if (node.body) { - parts.push(" ", group(print("body"))); - } else { - parts.push(options.semi ? ";" : ""); - } - - return parts; - } + case "TSModuleDeclaration": + return [ + printDeclareToken(path), + node.kind === "global" ? "" : `${node.kind} `, + print("id"), + node.body ? [" ", group(print("body"))] : options.semi ? ";" : "", + ]; case "TSConditionalType": return printTernary(path, options, print);