From 76e53696b498c85739c7dc25e8bd0e12ab5b31c4 Mon Sep 17 00:00:00 2001 From: wangzhiyusss Date: Wed, 13 Aug 2025 22:14:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=BB=E9=87=8D=E9=97=AE?= =?UTF-8?q?=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 | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/build-tools/intToNumber.js b/build-tools/intToNumber.js index 310be81d72..92a43c7f00 100644 --- a/build-tools/intToNumber.js +++ b/build-tools/intToNumber.js @@ -299,11 +299,15 @@ function parseJSDocVisitEachChild1(context, node) { * @param {content} 文本内容 */ function applJSDocTransformations(typeExpr, newTypeExpr, tagDataList, isChange) { + if (!typeExpr && !newTypeExpr) { + return; + } const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); const finalContent = printer.printNode(ts.EmitHint.Unspecified, 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 = { + isDelete: false, pos: typeExpr.pos, end: typeExpr.end, convertedText: '?' + `(${finalContent})` @@ -311,6 +315,7 @@ function applJSDocTransformations(typeExpr, newTypeExpr, tagDataList, isChange) tagDataList.push(data); } else { const data = { + isDelete: false, pos: typeExpr.pos, end: typeExpr.end, convertedText: '?' + finalContent @@ -319,6 +324,7 @@ function applJSDocTransformations(typeExpr, newTypeExpr, tagDataList, isChange) } } else if (finalContent.includes('number')) { const data = { + isDelete: true, pos: typeExpr.pos, end: typeExpr.end, convertedText: finalContent @@ -338,7 +344,11 @@ function changeContent(tagDataList) { for (const data of tagDataList) { const before = jsDocContent.substring(0, data.pos); const after = jsDocContent.substring(data.end); - jsDocContent = before + ` ${data.convertedText}` + after; + if (data.isDelete) { + jsDocContent = before + `${data.convertedText}` + after; + } else { + jsDocContent = before + ` ${data.convertedText}` + after; + } } } @@ -374,8 +384,13 @@ function parseJSDocVisitEachChild2(context, node) { } function writeDataToFile(tag) { const typeExpr = tag.typeExpression; - const newTypeExpr = parseTypeExpression(typeExpr.type); - applJSDocTransformations(typeExpr.type, newTypeExpr, tagDataList, false); + if (ts.isJSDocNullableType(node) && typeExpr.type.type) { + const newTypeExpr = parseTypeExpression(typeExpr.type.type); + applJSDocTransformations(typeExpr.type.type, newTypeExpr, tagDataList, false); + } else { + const newTypeExpr = parseTypeExpression(typeExpr.type); + applJSDocTransformations(typeExpr.type, newTypeExpr, tagDataList, false); + } } function parseTypeExpression(node) { if (ts.isUnionTypeNode(node)) { -- Gitee