From 03ba3fd54c398172788d424ebdeb41e518de4aa4 Mon Sep 17 00:00:00 2001 From: wangzhiyusss Date: Sat, 26 Jul 2025 16:51:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djsdoc=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhiyusss --- build-tools/intToNumber.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/build-tools/intToNumber.js b/build-tools/intToNumber.js index 310be81d72..6a7ea9149c 100644 --- a/build-tools/intToNumber.js +++ b/build-tools/intToNumber.js @@ -292,6 +292,29 @@ function parseJSDocVisitEachChild1(context, node) { } } +function printJSDocNode(node) { + const sourceFile = ts.createSourceFile( + 'temp.ts', + '', + ts.ScriptTarget.Latest, + false, + ts.ScriptKind.TS + ); + + const printer = ts.createPrinter({ + newLine: ts.NewLineKind.LineFeed, + removeComments: true + }); + + const raw = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile); + + return raw + .replace(/\s*;\s*/g, ', ') + .replace(/,\s*}$/, ' }') + .replace(/\s+/g, ' ') + .replace(/, \}/g, '}'); +} + /** * * @param {typeExpr} 原始typeExpr @@ -299,8 +322,7 @@ function parseJSDocVisitEachChild1(context, node) { * @param {content} 文本内容 */ function applJSDocTransformations(typeExpr, newTypeExpr, tagDataList, isChange) { - const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); - const finalContent = printer.printNode(ts.EmitHint.Unspecified, newTypeExpr); + const finalContent = printJSDocNode(newTypeExpr); if (finalContent.includes('number') && typeExpr.kind === ts.SyntaxKind.JSDocNullableType && !finalContent.includes('?number') && isChange) { if (typeExpr.type.type && typeExpr.type.type.kind === ts.SyntaxKind.UnionType) { const data = { -- Gitee