diff --git a/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/src/api_check_wrapper.ts b/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/src/api_check_wrapper.ts index fd43e761422d3a6747e7c1d91d86fec9d7a4b0ea..c8af7f6608ba1e75bbee64746b3f52bad2db08eb 100644 --- a/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/src/api_check_wrapper.ts +++ b/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/src/api_check_wrapper.ts @@ -28,6 +28,7 @@ import { import { SINCE_TAG_NAME } from "../../utils/api_check_plugin_define"; import { parseJSDoc } from '../custom-plugins/custom-comment-parser'; import { globalObject } from '../../index'; +import path from 'path'; export let curApiCheckWrapper: ApiCheckWrapper; export let curFileCheckModuleInfo: FileCheckModuleInfo; @@ -85,7 +86,7 @@ export function checkApiExpression(apiCheckHost: ApiCheckWrapperServiceHost, pee } if (currProgram.peer !== program.peer) { const name: string = fileNames.get(currProgram.peer)!; - if (legacyModuleList && matchPrefix(legacyModuleList, name)) { + if (globalObject.projectConfig.entryFiles.includes(path.normalize(currProgram.sourceFilePath))) { curApiCheckWrapper.fileName = currProgram.sourceFilePath; curFileCheckModuleInfo.currentFileName = currProgram.fileName; // 清空map对象 diff --git a/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/utils/ts_wrapper_node_util.ts b/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/utils/ts_wrapper_node_util.ts index 92898858d91d1bbae9be1deb088aa6f55838b96d..2a4626535b5ea0fde7bde944b84fc8234c356985 100644 --- a/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/utils/ts_wrapper_node_util.ts +++ b/build-tools/compile-plugins/api-check-plugin-static/api-check-wrapper/utils/ts_wrapper_node_util.ts @@ -16,6 +16,7 @@ import * as arkts from '@koalaui/libarkts'; import { checkIdentifier } from "../src/api_check_wrapper"; +// 不同节点对应的处理函数映射 export const nodeHandleFunctionMap = new Map void>([ [arkts.Es2pandaAstNodeType.AST_NODE_TYPE_ASSIGNMENT_EXPRESSION, handleAssignmentExpression], [arkts.Es2pandaAstNodeType.AST_NODE_TYPE_ANNOTATION_USAGE, handleAnnotatedAstNode], @@ -171,20 +172,52 @@ export const nodeHandleFunctionMap = new Map { + return matchArray.map(pair => { + // 直接将枚举值(数字)转换为字符串并拼接 + return pair.map(item => item.toString()).join('|'); + }); +}; +// 转换函数:将元组的数组最后4个元素拼接成字符串 +const joinLastFourElement = (nodePath: VisitNode[]): string => + nodePath.slice(-4).map(node => node[0]).join('|'); + +// 有效的节点校验路径列表(倒序,从子节点开始) +const validNodeTypePathList = [ + [ + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DECLARATION, + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_CLASS_DEFINITION, + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_ANNOTATION_USAGE, + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_IDENTIFIER + ] +] + +// 有效的节点校验路径列表(字符串版本) +const ValidNodeTypePathStrList = convertToNumberStringArray(validNodeTypePathList); /** + * * 根节点处理 * @param { arkts.AstNode } node */ -export function traverseProgram(node: arkts.AstNode):void { +export function traverseProgram(node: arkts.AstNode): void { // 处理Identifier if (!!node.statements) { node.statements.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -201,49 +234,53 @@ export function getJSDocInformation(node: arkts.AstNode): string { } /** - * 解析AST - * + * 检查节点是否访问次数超过上限 + * @param { arkts.AstNode } node 传入节点 + */ +function checkLimit(node: arkts.AstNode) { + if (nodeMap.has(node.peer.toString())) { + if (nodeMap.get(node.peer.toString()) > limitCount) { + return true; + } + if (isDebug && nodeMap.get(node.peer.toString()) > 2) { + console.error("[API_CHECK_PLUGIN] repeat traverse"); + } + nodeMap.set(node.peer.toString(), nodeMap.get(node.peer.toString()) + 1); + } else { + nodeMap.set(node.peer.toString(), 1); + } + return false; +} +/** + * 节点通用处理逻辑 * @param { arkts.AstNode } node 节点 - * @param { (node: any, ...args: any[]) => void } func 实际方法 */ -function handleFunction(node: arkts.AstNode, func: (node: any, ...args: any[]) => void):void { - if (isDebug) { - items.push([func.name, node.peer.toString()]); +function handleAstNode(node: arkts.AstNode): void { + // 用于判断是否重复访问或者陷入循环 + if (node == null || node == undefined || checkLimit(node)) { + return; } + // 通过CAPI获取节点具体类型 + let kind: number = arkts.arktsGlobal.generatedEs2panda._AstNodeTypeConst(arkts.arktsGlobal.context, node.peer) + if (!nodeHandleFunctionMap.has(kind) || nodeHandleFunctionMap.get(kind) === undefined) { + return; + } + // 根据类型获取到具体节点对应处理方法 + let func = nodeHandleFunctionMap.get(kind)! + // 添加当前节点到访问路径 + visitPath.push([kind, `${func.name}_${node.peer.toString()}`]); // Expression 下的identifier才会提示告警 if (node instanceof arkts.Expression) { exporssionCount++; } - if (node == null || node == undefined) { - return; - } - + // 编译节点属性 func(node); - if (isDebug) { - if (nodeMap.has(node.peer.toString())) { - if (nodeMap.get(node.peer.toString()) > 2) { - console.error("[API_CHECK_PLUGIN] repeat traverse"); - } - nodeMap.set(node.peer.toString(), nodeMap.get(node.peer.toString()) + 1); - } else { - nodeMap.set(node.peer.toString(), 1); - } - items.pop(); - } + // 清理节点 if (node instanceof arkts.Expression) { exporssionCount--; } -} - -export function handleAstNode(node: arkts.AstNode) { - if (isDebug) { - console.info('[API_CHECK_PLUGIN] handleAstNode'); - } - let kind: number = arkts.arktsGlobal.generatedEs2panda._AstNodeTypeConst(arkts.arktsGlobal.context, node.peer) - if (nodeHandleFunctionMap.has(kind) && nodeHandleFunctionMap.get(kind) !== undefined) { - handleFunction(node, nodeHandleFunctionMap.get(kind)!) - } + visitPath.pop(); } export function handleAnnotatedAstNode(node: arkts.AstNode) { } @@ -264,7 +301,7 @@ export function handleAnnotationDeclaration(node: arkts.AstNode) { node.properties.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -282,7 +319,7 @@ export function handleArrayExpression(node: arkts.AstNode) { node.elements.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.declarators) { - node.declarators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.declarators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeAnnotation) { handleAstNode(node.typeAnnotation); @@ -291,7 +328,7 @@ export function handleArrayExpression(node: arkts.AstNode) { export function handleArrowFunctionExpression(node: arkts.AstNode) { if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.scriptFunction) { handleAstNode(node.scriptFunction); @@ -356,10 +393,7 @@ export function handleBooleanLiteral(node: arkts.AstNode) { } export function handleBreakStatement(node: arkts.AstNode) { if (!!node.ident) { - handleFunction(node.ident, handleIdentifier); - } - if (!!node.target) { - handleAstNode(node.target); + handleAstNode(node.ident); } } @@ -400,16 +434,16 @@ export function handleCharLiteral(node: arkts.AstNode) { } export function handleClassDeclaration(node: arkts.AstNode) { if (!!node.definition) { - handleFunction(node.definition, handleClassDefinition); + handleAstNode(node.definition); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } export function handleClassDefinition(node: arkts.AstNode) { if (!!node.ident) { - handleFunction(node.ident, handleIdentifier); + handleAstNode(node.ident); } if (!!node.super) { handleAstNode(node.super); @@ -418,20 +452,23 @@ export function handleClassDefinition(node: arkts.AstNode) { node.body.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.implments) { - node.implments.forEach((item: arkts.AstNode) => handleFunction(item, handleTSClassImplements)); + node.implments.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.superTypeParams) { - handleFunction(node.superTypeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.superTypeParams); } if (!!node.origEnumDecl) { - handleFunction(node.origEnumDecl, handleTSEnumDeclaration); + handleAstNode(node.origEnumDecl); } if (!!node.getAnonClass) { handleAstNode(node.getAnonClass); } + if (!!node.annotations) { + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); + } } export function handleClassElement(node: arkts.AstNode) { @@ -442,13 +479,13 @@ export function handleClassElement(node: arkts.AstNode) { handleAstNode(node.value); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } export function handleClassExpression(node: arkts.AstNode) { if (!!node.definition) { - handleFunction(node.definition, handleClassDefinition); + handleAstNode(node.definition); } } @@ -457,7 +494,7 @@ export function handleClassProperty(node: arkts.AstNode) { handleAstNode(node.typeAnnotation); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.key) { handleAstNode(node.key); @@ -466,7 +503,7 @@ export function handleClassProperty(node: arkts.AstNode) { handleAstNode(node.value); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -478,7 +515,7 @@ export function handleClassStaticBlock(node: arkts.AstNode) { handleAstNode(node.value); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -502,7 +539,7 @@ export function handleContext(node: arkts.AstNode) { } */ export function handleContinueStatement(node: arkts.AstNode) { if (!!node.ident) { - handleFunction(node.ident, handleIdentifier); + handleAstNode(node.ident); } } @@ -549,7 +586,7 @@ export function handleETSClassLiteral(node: arkts.AstNode) { export function handleETSDynamicFunctionType(node: arkts.AstNode) { if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -564,7 +601,7 @@ export function handleETSDynamicFunctionType(node: arkts.AstNode) { export function handleETSFunctionType(node: arkts.AstNode) { if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -581,10 +618,10 @@ export function handleETSImportDeclaration(node: arkts.AstNode) { } export function handleETSModule(node: arkts.AstNode) { if (!!node.ident) { - handleFunction(node.ident, handleIdentifier); + handleAstNode(node.ident); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.statements) { node.statements.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -624,7 +661,7 @@ export function handleETSPackageDeclaration(node: arkts.AstNode) { } export function handleETSParameterExpression(node: arkts.AstNode) { if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.type) { handleAstNode(node.type); @@ -633,7 +670,7 @@ export function handleETSParameterExpression(node: arkts.AstNode) { handleAstNode(node.initializer); } if (!!node.identifier) { - handleFunction(node.identifier, handleIdentifier); + handleAstNode(node.identifier); } } @@ -642,16 +679,16 @@ export function handleETSPrimitiveType(node: arkts.AstNode) { export function handleETSReExportDeclaration(node: arkts.AstNode) { if (!!node.getETSImportDeclarations) { - handleFunction(node.getETSImportDeclarations, handleETSImportDeclaration); + handleAstNode(node.getETSImportDeclarations); } } export function handleETSStructDeclaration(node: arkts.AstNode) { if (!!node.definition) { - handleFunction(node.definition, handleClassDefinition); + handleAstNode(node.definition); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -663,19 +700,19 @@ export function handleETSTuple(node: arkts.AstNode) { export function handleETSTypeReference(node: arkts.AstNode) { if (!!node.part) { - handleFunction(node.part, handleETSTypeReferencePart); + handleAstNode(node.part); } } export function handleETSTypeReferencePart(node: arkts.AstNode) { if (!!node.previous) { - handleFunction(node.previous, handleETSTypeReferencePart); + handleAstNode(node.previous); } if (!!node.name) { handleAstNode(node.name); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParams); } } @@ -689,7 +726,7 @@ export function handleETSUnionType(node: arkts.AstNode) { export function handleETSWildcardType(node: arkts.AstNode) { if (!!node.typeReference) { - handleFunction(node.typeReference, handleETSTypeReference); + handleAstNode(node.typeReference); } } @@ -697,10 +734,10 @@ export function handleEmptyStatement(node: arkts.AstNode) { } export function handleExportAllDeclaration(node: arkts.AstNode) { if (!!node.source) { - handleFunction(node.source, handleStringLiteral); + handleAstNode(node.source); } if (!!node.exported) { - handleFunction(node.exported, handleIdentifier); + handleAstNode(node.exported); } } @@ -715,19 +752,19 @@ export function handleExportNamedDeclaration(node: arkts.AstNode) { handleAstNode(node.decl); } if (!!node.source) { - handleFunction(node.source, handleStringLiteral); + handleAstNode(node.source); } if (!!node.specifiers) { - node.specifiers.forEach((item: arkts.AstNode) => handleFunction(item, handleExportSpecifier)); + node.specifiers.forEach((item: arkts.AstNode) => handleAstNode(item)); } } export function handleExportSpecifier(node: arkts.AstNode) { if (!!node.local) { - handleFunction(node.local, handleIdentifier); + handleAstNode(node.local); } if (!!node.exported) { - handleFunction(node.exported, handleIdentifier); + handleAstNode(node.exported); } } @@ -780,16 +817,16 @@ export function handleForUpdateStatement(node: arkts.AstNode) { export function handleFunctionDecl(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.returnStatements) { - node.returnStatements.forEach((item: arkts.AstNode) => handleFunction(item, handleReturnStatement)); + node.returnStatements.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.body) { handleAstNode(node.body); @@ -798,13 +835,13 @@ export function handleFunctionDecl(node: arkts.AstNode) { handleAstNode(node.returnTypeAnnotation); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNde) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNde) => handleAstNode(item)); } } export function handleFunctionDeclaration(node: arkts.AstNode) { if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.scriptFunction) { handleAstNode(node.scriptFunction); @@ -813,13 +850,13 @@ export function handleFunctionDeclaration(node: arkts.AstNode) { node.parameters.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.name) { - handleFunction(node.name, handleIdentifier); + handleAstNode(node.name); } if (!!node.body) { handleAstNode(node.body); } if (!!node.typeParamsDecl) { - handleFunction(node.typeParamsDecl, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParamsDecl); } if (!!node.returnType) { handleAstNode(node.returnType); @@ -838,7 +875,7 @@ export function handleFunctionSignature(node: arkts.AstNode) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.returnType) { handleAstNode(node.returnType); @@ -846,12 +883,12 @@ export function handleFunctionSignature(node: arkts.AstNode) { } export function handleIdentifier(node: arkts.AstNode) { - if (exporssionCount > 1) { + if (exporssionCount > 1 || ValidNodeTypePathStrList.includes(joinLastFourElement(visitPath))) { checkIdentifier(node); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeAnnotation) { handleAstNode(node.typeAnnotation); @@ -875,69 +912,69 @@ export function handleImportDeclaration(node: arkts.AstNode) { export function handleImportDefaultSpecifier(node: arkts.AstNode) { if (!!node.local) { - handleFunction(node.local, handleIdentifier); + handleAstNode(node.local); } } export function handleImportExpression(node: arkts.AstNode) { if (!!node.source) { - handleFunction(node.source, handleStringLiteral); + handleAstNode(node.source); } } export function handleImportNamespaceSpecifier(node: arkts.AstNode) { if (!!node.local) { - handleFunction(node.local, handleIdentifier); + handleAstNode(node.local); } } export function handleImportSource(node: arkts.AstNode) { if (!!node.source) { - handleFunction(node.source, handleStringLiteral); + handleAstNode(node.source); } if (!!node.resolvedSource) { - handleFunction(node.resolvedSource, handleStringLiteral); + handleAstNode(node.resolvedSource); } } export function handleImportSpecifier(node: arkts.AstNode) { if (!!node.imported) { - handleFunction(node.imported, handleIdentifier); + handleAstNode(node.imported); } if (!!node.local) { - handleFunction(node.local, handleIdentifier); + handleAstNode(node.local); } } export function handleInterfaceDecl(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } if (!!node.body) { - handleFunction(node.body, handleTSInterfaceBody); + handleAstNode(node.body); } if (!!node.typeParams) { - handleFunction(node.typeParam, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParam); } if (!!node.extends) { - node.extends.forEach((item: arkts.TypeNode) => handleFunction(item, handleTSInterfaceHeritage)); + node.extends.forEach((item: arkts.TypeNode) => handleAstNode(item)); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.getAnonClass) { handleAstNode(node.getAnonClass); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } } export function handleLabelPair(node: arkts.AstNode) { if (!!node.ident) { - handleFunction(node.ident, handleIdentifier); + handleAstNode(node.ident); } if (!!node.body) { handleAstNode(node.body); @@ -965,13 +1002,13 @@ export function handleMetaProperty(node: arkts.AstNode) { } export function handleMethodDefinition(node: arkts.AstNode) { if (!!node.overloads) { - node.overloads.forEach((item: arkts.AstNode) => handleFunction(item, handleMethodDefinition)); + node.overloads.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.scriptFunction) { handleAstNode(node.scriptFunction); } if (!!node.name) { - handleFunction(node.name, handleIdentifier); + handleAstNode(node.name); } if (!!node.key) { handleAstNode(node.key); @@ -980,16 +1017,16 @@ export function handleMethodDefinition(node: arkts.AstNode) { handleAstNode(node.value); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } export function handleNamedType(node: arkts.AstNode) { if (!!node.name) { - handleFunction(node.name, handleIdentifier); + handleAstNode(node.name); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParams); } } @@ -1011,7 +1048,7 @@ export function handleObjectExpression(node: arkts.AstNode) { node.properties.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeAnnotation) { handleAstNode(node.typeAnnotation); @@ -1050,16 +1087,16 @@ export function handleReturnStatement(node: arkts.AstNode) { export function handleScriptFunction(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.returnStatements) { - node.returnStatements.forEach((item: arkts.AstNode) => handleFunction(item, handleReturnStatement)); + node.returnStatements.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.body) { handleAstNode(node.body); @@ -1068,7 +1105,7 @@ export function handleScriptFunction(node: arkts.AstNode) { handleAstNode(node.returnTypeAnnotation); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNde) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNde) => handleAstNode(item)); } } @@ -1083,7 +1120,7 @@ export function handleSpreadElement(node: arkts.AstNode) { handleAstNode(node.argument); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeAnnotation) { handleAstNode(node.typeAnnotation); @@ -1101,7 +1138,7 @@ export function handleStringLiteral(node: arkts.AstNode) { } export function handleSuperExpression(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } } @@ -1119,7 +1156,7 @@ export function handleSwitchStatement(node: arkts.AstNode) { handleAstNode(node.discriminant); } if (!!node.cases) { - node.cases.forEach((item: arkts.AstNode) => handleFunction(item, handleSwitchCaseStatement)); + node.cases.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -1150,7 +1187,7 @@ export function handleTSClassImplements(node: arkts.AstNode) { handleAstNode(node.expr); } if (!!node.typeParameters) { - handleFunction(node.typeParameters, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParameters); } } @@ -1171,7 +1208,7 @@ export function handleTSConditionalType(node: arkts.AstNode) { export function handleTSConstructorType(node: arkts.AstNode) { if (!!node.typeParams) { - handleFunction(node.typeParameters, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParameters); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -1183,16 +1220,16 @@ export function handleTSConstructorType(node: arkts.AstNode) { export function handleTSEnumDeclaration(node: arkts.AstNode) { if (!!node.key) { - handleFunction(node.key, handleIdentifier); + handleAstNode(node.key); } if (!!node.members) { node.members.forEach((item: arkts.AstNde) => handleAstNode(item)); } if (!!node.boxedClass) { - handleFunction(node.boxedClass, handleClassDefinition); + handleAstNode(node.boxedClass); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -1213,7 +1250,7 @@ export function handleTSExternalModuleReference(node: arkts.AstNode) { export function handleTSFunctionType(node: arkts.AstNode) { if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParams); } if (!!node.params) { node.params.forEach((item: arkts.TypeNode) => handleAstNode(item)); @@ -1225,7 +1262,7 @@ export function handleTSFunctionType(node: arkts.AstNode) { export function handleTSImportEqualsDeclaration(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } if (!!node.moduleReference) { handleAstNode(node.moduleReference); @@ -1234,7 +1271,7 @@ export function handleTSImportEqualsDeclaration(node: arkts.AstNode) { export function handleTSImportType(node: arkts.AstNode) { if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParams); } if (!!node.params) { handleAstNode(node.params); @@ -1264,7 +1301,7 @@ export function handleTSIndexedAccessType(node: arkts.AstNode) { export function handleTSInferType(node: arkts.AstNode) { if (!!node.typeParam) { - handleFunction(node.typeParam, handleTSTypeParameter); + handleAstNode(node.typeParam); } } @@ -1276,25 +1313,25 @@ export function handleTSInterfaceBody(node: arkts.AstNode) { export function handleTSInterfaceDeclaration(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } if (!!node.body) { - handleFunction(node.body, handleTSInterfaceBody); + handleAstNode(node.body); } if (!!node.typeParams) { - handleFunction(node.typeParam, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParam); } if (!!node.extends) { - node.extends.forEach((item: arkts.TypeNode) => handleFunction(item, handleTSInterfaceHeritage)); + node.extends.forEach((item: arkts.TypeNode) => handleAstNode(item)); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.getAnonClass) { handleAstNode(node.getAnonClass); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -1318,7 +1355,7 @@ export function handleTSLiteralType(node: arkts.AstNode) { export function handleTSMappedType(node: arkts.AstNode) { if (!!node.typeParameter) { - handleFunction(node.typeParameter, handleTSTypeParameter); + handleAstNode(node.typeParameter); } if (!!node.typeAnnotation) { handleAstNode(node.typeAnnotation); @@ -1330,7 +1367,7 @@ export function handleTSMethodSignature(node: arkts.AstNode) { handleAstNode(node.key); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -1404,13 +1441,13 @@ export function handleTSQualifiedName(node: arkts.AstNode) { handleAstNode(node.left); } if (!!node.right) { - handleFunction(node.right, handleIdentifier); + handleAstNode(node.right); } } export function handleTSSignatureDeclaration(node: arkts.AstNode) { if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.params) { node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -1432,16 +1469,16 @@ export function handleTSTupleType(node: arkts.AstNode) { export function handleTSTypeAliasDeclaration(node: arkts.AstNode) { if (!!node.id) { - handleFunction(node.id, handleIdentifier); + handleAstNode(node.id); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterDeclaration); + handleAstNode(node.typeParams); } if (!!node.decorators) { - node.decorators.forEach((item: arkts.AstNode) => handleFunction(item, handleDecorator)); + node.decorators.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.typeAnnotation) { handleAstNode(node.typeAnnotation); @@ -1475,7 +1512,7 @@ export function handleTSTypeOperator(node: arkts.AstNode) { export function handleTSTypeParameter(node: arkts.AstNode) { if (!!node.name) { - handleFunction(node.name, handleIdentifier); + handleAstNode(node.name); } if (!!node.constraint) { handleAstNode(node.constraint); @@ -1484,13 +1521,13 @@ export function handleTSTypeParameter(node: arkts.AstNode) { handleAstNode(node.defaultType); } if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } } export function handleTSTypeParameterDeclaration(node: arkts.AstNode) { if (!!node.params) { - node.params.forEach((item: arkts.AstNode) => handleFunction(item, handleTSTypeParameter)); + node.params.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -1520,7 +1557,7 @@ export function handleTSTypeReference(node: arkts.AstNode) { handleAstNode(node.typeName); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParams); } } @@ -1541,10 +1578,10 @@ export function handleTaggedTemplateExpression(node: arkts.AstNode) { handleAstNode(node.tag); } if (!!node.quasi) { - handleFunction(node.quasi, handleTemplateLiteral); + handleAstNode(node.quasi); } if (!!node.typeParams) { - handleFunction(node.typeParams, handleTSTypeParameterInstantiation); + handleAstNode(node.typeParams); } } @@ -1552,7 +1589,7 @@ export function handleTemplateElement(node: arkts.AstNode) { } export function handleTemplateLiteral(node: arkts.AstNode) { if (!!node.quasis) { - node.quasis.forEach((item: arkts.AstNode) => handleFunction(item, handleTemplateLiteral)); + node.quasis.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.expressions) { node.expressions.forEach((item: arkts.AstNode) => handleAstNode(item)); @@ -1575,7 +1612,7 @@ export function handleTryStatement(node: arkts.AstNode) { handleAstNode(node.block); } if (!!node.catchClauses) { - node.catchClauses.forEach((item: arkts.AstNode) => handleFunction(item, handleCatchClause)); + node.catchClauses.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -1609,10 +1646,10 @@ export function handleValidationInfo(node: arkts.AstNode) { } export function handleVariableDeclaration(node: arkts.AstNode) { if (!!node.annotations) { - node.annotations.forEach((item: arkts.AstNode) => handleFunction(item, handleAnnotationUsage)); + node.annotations.forEach((item: arkts.AstNode) => handleAstNode(item)); } if (!!node.declarators) { - node.declarators.forEach((item: arkts.AstNode) => handleFunction(item, handleVariableDeclarator)); + node.declarators.forEach((item: arkts.AstNode) => handleAstNode(item)); } } @@ -1621,7 +1658,7 @@ export function handleVariableDeclarator(node: arkts.AstNode) { handleAstNode(node.initializer); } if (!!node.name) { - handleFunction(node.name, handleIdentifier); + handleAstNode(node.name); } } diff --git a/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_typedef.ts b/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_typedef.ts index 77f1f9e272423eec59015bab7381b6c3b03059e4..cfbea5e64c88bee65db0e0c5f7a71b831f2a12da 100644 --- a/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_typedef.ts +++ b/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_typedef.ts @@ -76,6 +76,7 @@ export interface ProjectConfig extends ApiCheckConfig { deviceTypes: string[]; runtimeOS: string; dependentModuleList: DependentModuleConfig[]; + entryFiles: string[]; } export interface ApiCheckConfig { diff --git a/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_utils.ts b/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_utils.ts index 6ec3670fb15a6493a373bb09e53949cabfd23b54..8160eaeb3043600e5c0fa2a4b458f6b70b969193 100644 --- a/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_utils.ts +++ b/build-tools/compile-plugins/api-check-plugin-static/utils/api_check_plugin_utils.ts @@ -534,7 +534,8 @@ export function createOrCleanProjectConfig(): ProjectConfig { aceSoPath: '', sdkConfigPaths: '', initApiCheckTag: true, - dependentModuleList: [] + dependentModuleList: [], + entryFiles: [] }; }