From ff0f97c5901dc37669faf41f73882651de4b7f08 Mon Sep 17 00:00:00 2001 From: wangzhiyusss Date: Tue, 5 Aug 2025 05:53:33 +0000 Subject: [PATCH 1/3] update build-tools/package.json. Signed-off-by: wangzhiyusss --- build-tools/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools/package.json b/build-tools/package.json index ef7d9a08bf..a28fb3e7d7 100644 --- a/build-tools/package.json +++ b/build-tools/package.json @@ -13,6 +13,6 @@ "commander": "^13.1.0", "fs": "^0.0.1-security", "path": "^0.12.7", - "typescript": "npm:ohos-typescript@4.9.5-r8" + "typescript": "npm:ohos-typescript@4.9.5-r9" } } -- Gitee From e7f53fa8093f30eb2fc2842fbe572538d961616b Mon Sep 17 00:00:00 2001 From: wangzhiyusss Date: Tue, 5 Aug 2025 06:48:59 +0000 Subject: [PATCH 2/3] update build-tools/package-lock.json. Signed-off-by: wangzhiyusss --- build-tools/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-tools/package-lock.json b/build-tools/package-lock.json index c92425b8bf..aada908162 100644 --- a/build-tools/package-lock.json +++ b/build-tools/package-lock.json @@ -53,9 +53,9 @@ }, "node_modules/typescript": { "name": "ohos-typescript", - "version": "4.9.5-r8", - "resolved": "https://repo.huaweicloud.com/repository/npm/ohos-typescript/-/ohos-typescript-4.9.5-r8.tgz", - "integrity": "sha512-Wyj9xCBUOSMf7J1NsA82H75bpmA6Hm/U5V6yF62uz51XSq9spik57osyn/smAvPZqzrIhF/gRtPDYe0SWfqrAw==", + "version": "4.9.5-r9", + "resolved": "https://repo.huaweicloud.com/repository/npm/ohos-typescript/-/ohos-typescript-4.9.5-r9.tgz", + "integrity": "sha512-Hs7i6MKxHi15TjKK8qGiA75ejf0ggfF0L4F2GJ9XKLARu1hM5QQA395X+RwFYCjW76dqvf8s/CbhtiHNtackHg==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" -- Gitee From 0ca165d6f2fa2bc874cb6f94295f7a85d6a87d1d Mon Sep 17 00:00:00 2001 From: yangbo_404 Date: Sun, 3 Aug 2025 11:52:01 +0800 Subject: [PATCH 3/3] delete overload --- build-tools/delete_systemapi_plugin.js | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/build-tools/delete_systemapi_plugin.js b/build-tools/delete_systemapi_plugin.js index 163c6b9dad..83b8200ae0 100644 --- a/build-tools/delete_systemapi_plugin.js +++ b/build-tools/delete_systemapi_plugin.js @@ -41,6 +41,12 @@ const PATT = { REFERENCEURL_RIGHTSDK: /(..\/)(\S*)build-tools\/ets-loader\/declarations\/(\S*)/g, REFERENCEURL_SDK: /(..\/)(\S*)component\/(\S*)/g, }; +const METHOD_KIND = [ + ts.SyntaxKind.MethodDeclaration, + ts.SyntaxKind.FunctionDeclaration, + ts.SyntaxKind.MethodSignature, + ts.SyntaxKind.Constructor +]; function start() { const program = new commander.Command(); @@ -493,6 +499,59 @@ function writeFile(url, data, option) { const globalModules = new Map(); +/** + * 遍历处理overload节点 + * @param context 解析过后的内容 + * @param node 解析过后的节点 + * @returns ts.node + */ +function visitEachChild(context, node) { + return ts.visitEachChild(node, processAllNodes, context); // 遍历所有子节点 + function processAllNodes(node) { + if (ts.isOverloadDeclaration(node)) { + node = processInterfaceDeclaration(node); + } + return ts.visitEachChild(node, processAllNodes, context); + } + function processInterfaceDeclaration(overloadNode) { + // 获取方法类型兄弟节点列表 + const parentNode = overloadNode.parent; + const brotherNodes = []; + const brotherFuntionNames = new Set([]); + if (ts.isSourceFile(parentNode) || ts.isModuleBlock(parentNode)) { + brotherNodes.push(...parentNode.statements); + } else if (ts.isInterfaceDeclaration(parentNode) || ts.isClassDeclaration(parentNode)) { + brotherNodes.push(...parentNode.members); + } + if (brotherNodes.length === 0) { + return undefined; + } + brotherNodes.forEach(brotherNode => { + if (METHOD_KIND.includes(brotherNode.kind) && brotherNode.name && ts.isIdentifier(brotherNode.name) && + !brotherFuntionNames.has(brotherNode.name.escapedText.toString())) { + brotherFuntionNames.add(brotherNode.name.escapedText.toString()); + } + }); + + // 更新overload节点 + const overloadChildren = overloadNode.members; + if (overloadChildren.length === 0) { + return undefined; + } + const newChildren = []; + overloadChildren.forEach(overloadChild => { + if (overloadChild.name && ts.isIdentifier(overloadChild.name) && + brotherFuntionNames.has(overloadChild.name.escapedText.toString())) { + newChildren.push(overloadChild); + } + }); + if (newChildren.length === 0) { + return undefined; + } + return ts.factory.updateOverloadDeclaration(overloadNode, overloadNode.modifier, overloadNode.name, newChildren); + } +} + /** * 每个文件处理前回调函数第二个 * @param {string} url 文件路径 @@ -505,7 +564,7 @@ function formatImportDeclaration(url, copyrightMessage = '', isCopyrightDeleted sourceFile = node; collectAllIdentifier(node); // 获取所有标识符 formatValue = formatAllNodes(url, node, allIdentifierSet); // 获取所有节点 - node = formatValue.node; + node = visitEachChild(context, formatValue.node); const referencesMessage = formatValue.referencesMessage; if (formatValue.isCopyrightDeleted) { copyrightMessage = formatValue.copyrightMessage; -- Gitee