diff --git a/arkui-plugins/collectors/memo-collectors/factory.ts b/arkui-plugins/collectors/memo-collectors/factory.ts index e1d6e17454c127feec7599709a30a131149aec9a..6bc5b68d82155b64c82cf55f73dbd5c93a68671d 100644 --- a/arkui-plugins/collectors/memo-collectors/factory.ts +++ b/arkui-plugins/collectors/memo-collectors/factory.ts @@ -64,14 +64,14 @@ export class factory { static findAndCollectMemoableMethod(node: arkts.MethodDefinition): arkts.MethodDefinition { if (findCanAddMemoFromMethod(node)) { - addMemoAnnotation(node.scriptFunction); + addMemoAnnotation(node.function!); } return node; } static findAndCollectMemoableArrowFunction(node: arkts.ArrowFunctionExpression): arkts.ArrowFunctionExpression { if (findCanAddMemoFromArrowFunction(node)) { - addMemoAnnotation(node.scriptFunction); + addMemoAnnotation(node.function!); } return node; } diff --git a/arkui-plugins/collectors/memo-collectors/function-collector.ts b/arkui-plugins/collectors/memo-collectors/function-collector.ts index 2f9d07b8ce41349e4bfa04de26dee4904c038fad..90a6c6c040bc2593778a5d77b15bf81e2da3ca38 100644 --- a/arkui-plugins/collectors/memo-collectors/function-collector.ts +++ b/arkui-plugins/collectors/memo-collectors/function-collector.ts @@ -92,7 +92,7 @@ export class MemoFunctionCollector extends AbstractVisitor { return node; } if (arkts.isArrowFunctionExpression(node.initializer)) { - const func = node.initializer.scriptFunction; + const func = node.initializer.function!; const localInfo = collectMemoableInfoInScriptFunction(func); const shouldCollectParameter = (localInfo.hasBuilder || localInfo.hasMemo) && !localInfo.hasMemoEntry && !localInfo.hasMemoIntrinsic; @@ -217,7 +217,7 @@ export class MemoFunctionCollector extends AbstractVisitor { if ( arkts.isArrowFunctionExpression(node) && !arkts.NodeCache.getInstance().has(node) && - !arkts.NodeCache.getInstance().has(node.scriptFunction) + !arkts.NodeCache.getInstance().has(node.function!) ) { this.shouldCollectReturn = false; } diff --git a/arkui-plugins/collectors/memo-collectors/utils.ts b/arkui-plugins/collectors/memo-collectors/utils.ts index 306df073108794fb2c11bb13b94222b1b2004072..68e1d176444205862624cce080bafa1f9d9e22a8 100644 --- a/arkui-plugins/collectors/memo-collectors/utils.ts +++ b/arkui-plugins/collectors/memo-collectors/utils.ts @@ -286,7 +286,7 @@ export function collectMemoableInfoInVariableDeclarator(node: arkts.AstNode, inf if (arkts.isMethodDefinition(decl)) { currInfo = { ...currInfo, - ...collectMemoableInfoInScriptFunction(decl.scriptFunction), + ...collectMemoableInfoInScriptFunction(decl.function!), }; } else if (arkts.isClassProperty(decl)) { currInfo = { @@ -311,25 +311,25 @@ export function collectMemoableInfoInProperty(node: arkts.AstNode, info?: Memoab if (!decl || !arkts.isMethodDefinition(decl)) { return currInfo; } - const hasReceiver = decl.scriptFunction.hasReceiver; + const hasReceiver = decl.function!.hasReceiver; const isSetter = decl.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET; const isGetter = decl.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET; let newInfo: MemoableInfo = {}; - if (isSetter && decl.scriptFunction.params.length > 0) { - if (hasReceiver && decl.scriptFunction.params.length === 2) { - newInfo = collectMemoableInfoInParameter(decl.scriptFunction.params.at(1)!); + if (isSetter && decl.function!.params.length > 0) { + if (hasReceiver && decl.function!.params.length === 2) { + newInfo = collectMemoableInfoInParameter(decl.function!.params.at(1)!); } else { - newInfo = collectMemoableInfoInParameter(decl.scriptFunction.params.at(0)!); + newInfo = collectMemoableInfoInParameter(decl.function!.params.at(0)!); } } else if (isGetter) { - newInfo = collectMemoableInfoInFunctionReturnType(decl.scriptFunction); + newInfo = collectMemoableInfoInFunctionReturnType(decl.function!); } - currInfo = { ...currInfo, ...collectMemoableInfoInScriptFunction(decl.scriptFunction), ...newInfo }; + currInfo = { ...currInfo, ...collectMemoableInfoInScriptFunction(decl.function!), ...newInfo }; currInfo.hasProperType = false; if (!!node.value && arkts.isArrowFunctionExpression(node.value)) { currInfo = { ...currInfo, - ...collectMemoableInfoInScriptFunction(node.value.scriptFunction), + ...collectMemoableInfoInScriptFunction(node.value.function!), }; } return currInfo; @@ -369,10 +369,10 @@ export function collectMemoableInfoInArrowFunction(node: arkts.AstNode, info?: M } currInfo.hasProperType = true; currInfo = { ...currInfo, ...hasMemoableAnnotation(node) }; - if (!!node.scriptFunction) { + if (!!node.function!) { currInfo = { ...currInfo, - ...collectMemoableInfoInScriptFunction(node.scriptFunction), + ...collectMemoableInfoInScriptFunction(node.function!), }; } if (!!node.parent && arkts.isAssignmentExpression(node.parent) && !!node.parent.left) { @@ -405,20 +405,20 @@ export function collectMemoableInfoInScriptFunction(node: arkts.AstNode, info?: } export function collectMemoableInfoInMethod(node: arkts.MethodDefinition): MemoableInfo { - const hasReceiver = node.scriptFunction.hasReceiver; + const hasReceiver = node.function!.hasReceiver; const isSetter = node.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET; const isGetter = node.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET; let info: MemoableInfo = {}; - if (isSetter && node.scriptFunction.params.length > 0) { - if (hasReceiver && node.scriptFunction.params.length === 2) { - info = collectMemoableInfoInParameter(node.scriptFunction.params.at(1)!); + if (isSetter && node.function!.params.length > 0) { + if (hasReceiver && node.function!.params.length === 2) { + info = collectMemoableInfoInParameter(node.function!.params.at(1)!); } else { - info = collectMemoableInfoInParameter(node.scriptFunction.params.at(0)!); + info = collectMemoableInfoInParameter(node.function!.params.at(0)!); } } else if (isGetter) { - info = collectMemoableInfoInFunctionReturnType(node.scriptFunction); + info = collectMemoableInfoInFunctionReturnType(node.function!); } - return collectMemoableInfoInScriptFunction(node.scriptFunction, info); + return collectMemoableInfoInScriptFunction(node.function!, info); } export function collectMemoableInfoInType(node: arkts.AstNode, info?: MemoableInfo): MemoableInfo { @@ -480,7 +480,7 @@ export function collectGensymDeclarator(declarator: arkts.VariableDeclarator, in arrowFunc = alternate; } if (!!arrowFunc) { - const func = arrowFunc.scriptFunction; + const func = arrowFunc.function!; const returnMemoableInfo = collectMemoableInfoInFunctionReturnType(func); collectScriptFunctionReturnTypeFromInfo(func, returnMemoableInfo); const [paramMemoableInfoMap, gensymCount] = collectMemoableInfoMapInFunctionParams(func); @@ -628,7 +628,7 @@ export function findCanAddMemoFromArrowFunction(node: arkts.AstNode): node is ar } const memoableInfo = collectMemoableInfoInArrowFunction(node); const { hasMemoEntry, hasMemoIntrinsic } = memoableInfo; - const func = node.scriptFunction; + const func = node.function!; const returnMemoableInfo = collectMemoableInfoInFunctionReturnType(func); collectScriptFunctionReturnTypeFromInfo(func, returnMemoableInfo); const [paramMemoableInfoMap, gensymCount] = collectMemoableInfoMapInFunctionParams( @@ -679,7 +679,7 @@ export function findCanAddMemoFromMethod(node: arkts.AstNode): node is arkts.Met } const memoableInfo = collectMemoableInfoInMethod(node); const { hasMemoEntry, hasMemoIntrinsic } = memoableInfo; - const func = node.scriptFunction; + const func = node.function!; const returnMemoableInfo = collectMemoableInfoInFunctionReturnType(func); collectScriptFunctionReturnTypeFromInfo(func, returnMemoableInfo); const [paramMemoableInfoMap, gensymCount] = collectMemoableInfoMapInFunctionParams( @@ -753,10 +753,10 @@ export function collectCallWithDeclaredClassProperty(node: arkts.CallExpression, } export function collectCallWithDeclaredMethod(node: arkts.CallExpression, decl: arkts.MethodDefinition): boolean { - const hasReceiver = decl.scriptFunction.hasReceiver; - const params = decl.scriptFunction.params; + const hasReceiver = decl.function!.hasReceiver; + const params = decl.function!.params; const args = node.arguments; - const hasRestParameter = decl.scriptFunction.hasRestParameter; + const hasRestParameter = decl.function!.hasRestParameter; const isTrailingCall = node.isTrailingCall; const options = { hasRestParameter, isTrailingCall }; forEachArgWithParam(args, params, collectCallArgsWithMethodParams, options); @@ -765,7 +765,7 @@ export function collectCallWithDeclaredMethod(node: arkts.CallExpression, decl: arkts.NodeCache.getInstance().collect(node, { hasReceiver, hasMemoEntry, hasMemoIntrinsic }); return true; } else { - const memoableInfo = collectMemoableInfoInScriptFunction(decl.scriptFunction); + const memoableInfo = collectMemoableInfoInScriptFunction(decl.function!); if (checkIsMemoFromMemoableInfo(memoableInfo, true)) { const { hasMemoEntry, hasMemoIntrinsic } = memoableInfo; arkts.NodeCache.getInstance().collect(node, { hasReceiver, hasMemoEntry, hasMemoIntrinsic }); @@ -787,7 +787,7 @@ export function collectCallArgsWithMethodParams(arg: arkts.Expression | undefine } if (checkIsMemoFromMemoableInfo(info) && arkts.isArrowFunctionExpression(arg)) { arkts.NodeCache.getInstance().collect(arg); - const func = arg.scriptFunction; + const func = arg.function!; const returnMemoableInfo = collectMemoableInfoInFunctionReturnType(func); collectScriptFunctionReturnTypeFromInfo(func, returnMemoableInfo); const [paramMemoableInfoMap, gensymCount] = collectMemoableInfoMapInFunctionParams(func); @@ -839,7 +839,7 @@ export function collectMemoScriptFunctionBody( export function collectMetadataInMethod(node: arkts.MethodDefinition): arkts.AstNodeCacheValue['metadata'] { const callName = node.name.name; - const hasReceiver = node.scriptFunction.hasReceiver; + const hasReceiver = node.function!.hasReceiver; const isSetter = node.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET; const isGetter = node.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET; return { callName, hasReceiver, isSetter, isGetter }; diff --git a/arkui-plugins/common/arkts-utils.ts b/arkui-plugins/common/arkts-utils.ts index 1b01d924856e72a453897a32d3fbf7dbefd5098d..f0fdb0e0e25670a0585da81d4f3e9edc6cd1994a 100644 --- a/arkui-plugins/common/arkts-utils.ts +++ b/arkui-plugins/common/arkts-utils.ts @@ -27,12 +27,10 @@ export function createAndInsertImportDeclaration( importKind: arkts.Es2pandaImportKinds, program: arkts.Program ): void { - const importDecl: arkts.ETSImportDeclaration = arkts.factory.createImportDeclaration( + const importDecl: arkts.ETSImportDeclaration = arkts.factory.createETSImportDeclaration( source, [arkts.factory.createImportSpecifier(imported, local)], - importKind, - program, - arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE + importKind ); arkts.importDeclarationInsert(importDecl, program); return; @@ -44,7 +42,7 @@ export function isNumeric(str: string): boolean { export function annotation(name: string): arkts.AnnotationUsage { const ident: arkts.Identifier = arkts.factory.createIdentifier(name).setAnnotationUsage(); - const annotation: arkts.AnnotationUsage = arkts.factory.createAnnotationUsage(ident); + const annotation: arkts.AnnotationUsage = arkts.factory.createAnnotationUsage(ident, []); annotation.modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_ANNOTATION_USAGE; ident.parent = annotation; diff --git a/arkui-plugins/common/declaration-collector.ts b/arkui-plugins/common/declaration-collector.ts index d65f0d40da094bc237037b592d7b699e322c77bd..0ac8cb543a8e8b1e7a7503606089c0cf6efe319d 100644 --- a/arkui-plugins/common/declaration-collector.ts +++ b/arkui-plugins/common/declaration-collector.ts @@ -51,13 +51,13 @@ export class DeclarationCollector { if (arkts.isAnnotationDeclaration(decl) && !!decl.expr && arkts.isIdentifier(decl.expr)) { declName = decl.expr.name; } else if (arkts.isMethodDefinition(decl)) { - declName = decl.name.name; + declName = decl.id!.name; } else if (arkts.isIdentifier(decl)) { declName = decl.name; } else if (arkts.isClassProperty(decl) && !!decl.key && arkts.isIdentifier(decl.key)) { declName = decl.key.name; - } else if (arkts.isEtsParameterExpression(decl)) { - declName = decl.identifier.name; + } else if (arkts.isETSParameterExpression(decl)) { + declName = decl.ident!.name; } if (!declName) { return; diff --git a/arkui-plugins/common/etsglobal-remover.ts b/arkui-plugins/common/etsglobal-remover.ts index 3d9711799c01b776e626fea84429fae186a05e3b..6a4d91b5f666ad2eb7fedc964051922591dc4f76 100644 --- a/arkui-plugins/common/etsglobal-remover.ts +++ b/arkui-plugins/common/etsglobal-remover.ts @@ -20,11 +20,11 @@ const ETSGLOBAL = 'ETSGLOBAL'; export class EtsglobalRemover extends AbstractVisitor { visitor(node: arkts.AstNode): arkts.AstNode { - if (arkts.isEtsScript(node)) { + if (arkts.isETSModule(node)) { const keep = node.statements.filter((it) => { return !(arkts.isClassDeclaration(it) && it.definition?.ident?.name == ETSGLOBAL); }); - return arkts.factory.updateEtsScript(node, keep); + return arkts.factory.updateETSModule(node, keep, node.ident, node.getNamespaceFlag()); } return node; } diff --git a/arkui-plugins/common/import-collector.ts b/arkui-plugins/common/import-collector.ts index 935b339af29f87951a69cc85508b64f1fa83e810..0a1e9b513fbbb1993f60e62348102419feb9985a 100644 --- a/arkui-plugins/common/import-collector.ts +++ b/arkui-plugins/common/import-collector.ts @@ -24,7 +24,7 @@ interface ImportInfo { } function insertImport(importInfo: ImportInfo, program?: arkts.Program): void { - const source: arkts.StringLiteral = arkts.factory.create1StringLiteral(importInfo.source); + const source: arkts.StringLiteral = arkts.factory.createStringLiteral(importInfo.source); const imported: arkts.Identifier = arkts.factory.createIdentifier(importInfo.imported); const local: arkts.Identifier = arkts.factory.createIdentifier(importInfo.local); // Insert this import at the top of the script's statements. @@ -73,7 +73,7 @@ export class ImportCollector { collectImport( imported: string, local?: string, - kind: arkts.Es2pandaImportKinds = arkts.Es2pandaImportKinds.IMPORT_KINDS_TYPE + kind: arkts.Es2pandaImportKinds = arkts.Es2pandaImportKinds.IMPORT_KINDS_TYPES ): void { if (!this.sourceMap.has(imported)) { throw new Error(`ImportCollector: import ${imported}'s source haven't been collected yet.`); diff --git a/arkui-plugins/common/plugin-context.ts b/arkui-plugins/common/plugin-context.ts index f661350a0fbf5d86de9efddb843f24c66dac55a1..bd38aed1bd12064cb6d5f02fc5ab89b4c7786167 100644 --- a/arkui-plugins/common/plugin-context.ts +++ b/arkui-plugins/common/plugin-context.ts @@ -17,7 +17,7 @@ import * as arkts from '@koalaui/libarkts'; // This is the same plugin-context in the build-system. export class PluginContext { - private ast: arkts.EtsScript | undefined; + private ast: arkts.ETSModule | undefined; private program: arkts.Program | undefined; private projectConfig: ProjectConfig | undefined; private contextPtr: number | undefined; @@ -34,14 +34,14 @@ export class PluginContext { /** * @deprecated */ - public setArkTSAst(ast: arkts.EtsScript): void { + public setArkTSAst(ast: arkts.ETSModule): void { this.ast = ast; } /** * @deprecated */ - public getArkTSAst(): arkts.EtsScript | undefined { + public getArkTSAst(): arkts.ETSModule | undefined { return this.ast; } diff --git a/arkui-plugins/common/program-visitor.ts b/arkui-plugins/common/program-visitor.ts index 55ac1aad41e3b936d0d1faeeb5d037b98db90c66..76d0b32542a6df10139a770fe4f70e2fa73e7fea 100644 --- a/arkui-plugins/common/program-visitor.ts +++ b/arkui-plugins/common/program-visitor.ts @@ -69,7 +69,7 @@ export class ProgramVisitor extends AbstractVisitor { private readonly visitors: AbstractVisitor[]; private readonly skipPrefixNames: (string | RegExp)[]; private readonly hooks?: ProgramHooks; - private filenames: Map; + private filenames: Map; private pluginContext?: PluginContext; private legacyModuleList: string[] = []; private legacyStructMap: Map; @@ -130,7 +130,7 @@ export class ProgramVisitor extends AbstractVisitor { private visitLegacyInExternalSource(currProgram: arkts.Program, name: string): void { if (this.state === arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED) { - const structList = this.visitorLegacy(currProgram.astNode, currProgram, name); + const structList = this.visitorLegacy(currProgram.ast, currProgram, name); const moduleName = name.split('/')[0]; const structMap = this.legacyStructMap.get(moduleName)!; for (const struct of structList) { @@ -146,8 +146,8 @@ export class ProgramVisitor extends AbstractVisitor { cachePath?: string ): void { const extensionName: string = program.fileNameWithExtension; - this.dumpExternalSource(currProgram.astNode, name, cachePath, 'ORI', extensionName); - const script = this.visitor(currProgram.astNode, currProgram, name); + this.dumpExternalSource(currProgram.ast, name, cachePath, 'ORI', extensionName); + const script = this.visitor(currProgram.ast, currProgram, name); if (script) { this.dumpExternalSource(script, name, cachePath, this.pluginName, extensionName); } @@ -176,7 +176,7 @@ export class ProgramVisitor extends AbstractVisitor { this.getLegacyModule(); while (queue.length > 0) { const currProgram = queue.shift()!; - if (visited.has(currProgram.peer) || currProgram.isASTLowered()) { + if (visited.has(currProgram.peer) || currProgram.isASTLowered) { continue; } if (currProgram.peer !== program.peer) { @@ -201,7 +201,7 @@ export class ProgramVisitor extends AbstractVisitor { programVisitor(program: arkts.Program): arkts.Program { this.visitExternalSources(program, [program]); - let programScript = program.astNode; + let programScript = program.ast; programScript = this.visitor(programScript, program, this.externalSourceName); const visitorsToReset = flattenVisitorsInHooks(this.hooks, this.state); @@ -216,7 +216,7 @@ export class ProgramVisitor extends AbstractVisitor { program?: arkts.Program, externalSourceName?: string ): void { - let script: arkts.EtsScript = node as arkts.EtsScript; + let script: arkts.ETSModule = node as arkts.ETSModule; const preVisitors = hook?.pre?.visitors ?? []; for (const transformer of preVisitors) { this.visitTransformer(transformer, script, externalSourceName, program); @@ -232,7 +232,7 @@ export class ProgramVisitor extends AbstractVisitor { program?: arkts.Program, externalSourceName?: string ): void { - let script: arkts.EtsScript = node as arkts.EtsScript; + let script: arkts.ETSModule = node as arkts.ETSModule; const postVisitors = hook?.post?.visitors ?? []; for (const transformer of postVisitors) { this.visitTransformer(transformer, script, externalSourceName, program); @@ -242,10 +242,10 @@ export class ProgramVisitor extends AbstractVisitor { } } - visitor(node: arkts.AstNode, program?: arkts.Program, externalSourceName?: string): arkts.EtsScript { + visitor(node: arkts.AstNode, program?: arkts.Program, externalSourceName?: string): arkts.ETSModule { let hook: ProgramHookLifeCycle | undefined; - let script: arkts.EtsScript = node as arkts.EtsScript; + let script: arkts.ETSModule = node as arkts.ETSModule; let count: number = 0; const isExternal: boolean = !!externalSourceName; @@ -290,14 +290,14 @@ export class ProgramVisitor extends AbstractVisitor { private visitTransformer( transformer: AbstractVisitor, - script: arkts.EtsScript, + script: arkts.ETSModule, externalSourceName?: string, program?: arkts.Program - ): arkts.EtsScript { + ): arkts.ETSModule { transformer.isExternal = !!externalSourceName; transformer.externalSourceName = externalSourceName; transformer.program = program; - const newScript = transformer.visitor(script) as arkts.EtsScript; + const newScript = transformer.visitor(script) as arkts.ETSModule; return newScript; } } diff --git a/arkui-plugins/interop-plugins/decl_transformer.ts b/arkui-plugins/interop-plugins/decl_transformer.ts index 7e5d73af9f1c95e74f907896e8ff1fbbff8a09ff..cea30659e80648483b2b1b4d16939fde01ad4ef2 100644 --- a/arkui-plugins/interop-plugins/decl_transformer.ts +++ b/arkui-plugins/interop-plugins/decl_transformer.ts @@ -24,7 +24,7 @@ export class DeclTransformer extends AbstractVisitor { super(); } - processComponent(node: arkts.StructDeclaration): arkts.ClassDeclaration { + processComponent(node: arkts.ETSStructDeclaration): arkts.ClassDeclaration { const className = node.definition?.ident?.name; if (!className) { throw 'Non Empty className expected for Component'; @@ -52,13 +52,13 @@ export class DeclTransformer extends AbstractVisitor { visitor(beforeChildren: arkts.AstNode): arkts.AstNode { let astNode: arkts.AstNode = beforeChildren; - if (arkts.isEtsScript(astNode)) { + if (arkts.isETSModule(astNode)) { astNode = this.transformImportDecl(astNode); } const node = this.visitEachChild(astNode); - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { debugLog(`DeclTransformer:before:flag:${arkts.classDefinitionIsFromStructConst(node.definition!)}`); - arkts.classDefinitionSetFromStructModifier(node.definition!); + node.definition!.setFromStructModifier(); let newnode = this.processComponent(node); debugLog(`DeclTransformer:after:flag:${arkts.classDefinitionIsFromStructConst(newnode.definition!)}`); return newnode; @@ -74,7 +74,7 @@ export class DeclTransformer extends AbstractVisitor { } transformImportDecl(astNode: arkts.AstNode):arkts.AstNode { - if (!arkts.isEtsScript(astNode)) { + if (!arkts.isETSModule(astNode)) { return astNode; } let statements = astNode.statements.filter(node => this.isImportDeclarationNeedFilter(node)); @@ -82,9 +82,9 @@ export class DeclTransformer extends AbstractVisitor { } transformMethodDefinition(node: arkts.MethodDefinition): arkts.AstNode { - const func: arkts.ScriptFunction = node.scriptFunction; + const func: arkts.ScriptFunction = node.function!; const isFunctionCall: boolean = false; - const typeNode: arkts.TypeNode | undefined = node.scriptFunction?.returnTypeAnnotation; + const typeNode: arkts.TypeNode | undefined = node.function?.returnTypeAnnotation; const updateFunc = arkts.factory.updateScriptFunction( func, !!func.body && arkts.isBlockStatement(func.body) diff --git a/arkui-plugins/memo-plugins/function-transformer.ts b/arkui-plugins/memo-plugins/function-transformer.ts index 4f2c55f1f4c572c8cabfa2ede178bc0d0cc1018d..05e6facbbd1b057921102a7541a0aa1be119f6fe 100644 --- a/arkui-plugins/memo-plugins/function-transformer.ts +++ b/arkui-plugins/memo-plugins/function-transformer.ts @@ -301,17 +301,17 @@ export class FunctionTransformer extends AbstractVisitor { const that = this; const updateOverloads = node.overloads?.map((overload) => that.visitor(overload)) ?? undefined; const isMemo = - hasMemoAnnotation(node.scriptFunction) || - hasMemoIntrinsicAnnotation(node.scriptFunction) || - hasMemoEntryAnnotation(node.scriptFunction); - if (isMemo && node.scriptFunction.body) { - const hasIntrinsic = hasMemoIntrinsicAnnotation(node.scriptFunction); + hasMemoAnnotation(node.function!) || + hasMemoIntrinsicAnnotation(node.function!) || + hasMemoEntryAnnotation(node.function!); + if (isMemo && node.function!.body) { + const hasIntrinsic = hasMemoIntrinsicAnnotation(node.function!); updateMethod = arkts.factory.updateMethodDefinition( node, node.kind, node.name, this.signatureTransformer.visitor( - removeMemoAnnotation(this.updateScriptFunction(node.scriptFunction, node.name.name)), + removeMemoAnnotation(this.updateScriptFunction(node.function!, node.name.name)), hasIntrinsic ), node.modifiers, @@ -322,7 +322,7 @@ export class FunctionTransformer extends AbstractVisitor { node, node.kind, node.name, - this.signatureTransformer.visitor(node.scriptFunction), + this.signatureTransformer.visitor(node.function!), node.modifiers, false ); @@ -340,13 +340,13 @@ export class FunctionTransformer extends AbstractVisitor { ignoreSelf: boolean = false ): arkts.CallExpression { let updatedArguments: arkts.AstNode[] = node.arguments.map((it, index) => { - const param = decl.scriptFunction.params.at(index); + const param = decl.function!.params.at(index); if (!param || !arkts.isEtsParameterExpression(param)) { return it; } if (isMemoETSParameterExpression(param) && arkts.isArrowFunctionExpression(it)) { - this.enterAnonymousScope(it.scriptFunction); - const res = this.updateScriptFunction(it.scriptFunction); + this.enterAnonymousScope(it.function!); + const res = this.updateScriptFunction(it.function!); this.exitAnonymousScope(); this.modified = true; return arkts.factory.updateArrowFunction(it, res); @@ -361,10 +361,10 @@ export class FunctionTransformer extends AbstractVisitor { ]; } const isMemo = - hasMemoAnnotation(decl.scriptFunction) || - hasMemoIntrinsicAnnotation(decl.scriptFunction) || - hasMemoEntryAnnotation(decl.scriptFunction); - if (parametrizedNodeHasReceiver(decl.scriptFunction) && isMemo) { + hasMemoAnnotation(decl.function!) || + hasMemoIntrinsicAnnotation(decl.function!) || + hasMemoEntryAnnotation(decl.function!); + if (parametrizedNodeHasReceiver(decl.function!) && isMemo) { updatedArguments = moveToFront(updatedArguments, 2); } this.modified = true; @@ -381,14 +381,14 @@ export class FunctionTransformer extends AbstractVisitor { if (isStandaloneArrowFunction(node.expression)) { newExpression = arkts.factory.updateArrowFunction( node.expression, - this.signatureTransformer.visitor(node.expression.scriptFunction) + this.signatureTransformer.visitor(node.expression.function!) ); } const that = this; const updatedArguments: arkts.AstNode[] = node.arguments.map((it) => { if (arkts.isArrowFunctionExpression(it) && isMemoArrowFunction(it)) { - that.enterAnonymousScope(it.scriptFunction); - const res = that.updateScriptFunction(it.scriptFunction); + that.enterAnonymousScope(it.function!); + const res = that.updateScriptFunction(it.function!); that.exitAnonymousScope(); that.modified = true; return arkts.factory.updateArrowFunction(it, res); @@ -404,7 +404,7 @@ export class FunctionTransformer extends AbstractVisitor { expression: arkts.ArrowFunctionExpression ): arkts.CallExpression { const scope = this.scopes[this.scopes.length - 1]; - const isValidScope = !!scope && scope.name === expression.scriptFunction.id?.name; + const isValidScope = !!scope && scope.name === expression.function!.id?.name; if (!isValidScope) { return node; } @@ -414,8 +414,8 @@ export class FunctionTransformer extends AbstractVisitor { } this.checkMemoCallInFunction(); - this.enterAnonymousScope(expression.scriptFunction); - const res = this.updateScriptFunction(expression.scriptFunction, expression.scriptFunction.id?.name); + this.enterAnonymousScope(expression.function!); + const res = this.updateScriptFunction(expression.function!, expression.function!.id?.name); this.exitAnonymousScope(); const newNode = this.updateAnonymousCallWithMemoParams(node); @@ -477,8 +477,8 @@ export class FunctionTransformer extends AbstractVisitor { let res: arkts.ScriptFunction | undefined; if (!!node.value && arkts.isArrowFunctionExpression(node.value)) { - this.enterAnonymousScope(node.value.scriptFunction); - res = this.updateScriptFunction(node.value.scriptFunction, key.name); + this.enterAnonymousScope(node.value.function!); + res = this.updateScriptFunction(node.value.function!, key.name); this.exitAnonymousScope(); } @@ -532,17 +532,17 @@ export class FunctionTransformer extends AbstractVisitor { private updateStandaloneArrowFunction(node: arkts.ArrowFunctionExpression): arkts.ArrowFunctionExpression { const scope = this.scopes[this.scopes.length - 1]; - const isValidScope = !!scope && scope.name === node.scriptFunction.id?.name; + const isValidScope = !!scope && scope.name === node.function!.id?.name; if (!isValidScope) { return node; } this.exitAnonymousScope(); if (!scope.isMemo) { - return arkts.factory.updateArrowFunction(node, this.signatureTransformer.visitor(node.scriptFunction)); + return arkts.factory.updateArrowFunction(node, this.signatureTransformer.visitor(node.function!)); } - this.enterAnonymousScope(node.scriptFunction); - const res = this.updateScriptFunction(node.scriptFunction, node.scriptFunction.id?.name); + this.enterAnonymousScope(node.function!); + const res = this.updateScriptFunction(node.function!, node.function!.id?.name); this.exitAnonymousScope(); this.modified = true; @@ -564,7 +564,7 @@ export class FunctionTransformer extends AbstractVisitor { node.name, arkts.factory.updateArrowFunction( node.initializer, - this.signatureTransformer.visitor(node.initializer.scriptFunction) + this.signatureTransformer.visitor(node.initializer.function!) ) ); } @@ -582,8 +582,8 @@ export class FunctionTransformer extends AbstractVisitor { let initializer: arkts.AstNode | undefined = node.initializer; if (!!initializer && arkts.isArrowFunctionExpression(initializer)) { - this.enterAnonymousScope(initializer.scriptFunction); - const res = this.updateScriptFunction(initializer.scriptFunction, initializer.scriptFunction.id?.name); + this.enterAnonymousScope(initializer.function!); + const res = this.updateScriptFunction(initializer.function!, initializer.function!.id?.name); this.exitAnonymousScope(); initializer = arkts.factory.updateArrowFunction(initializer, res); } @@ -611,8 +611,8 @@ export class FunctionTransformer extends AbstractVisitor { return node; } - this.enterAnonymousScope(expr.scriptFunction); - const res = this.updateScriptFunction(expr.scriptFunction, expr.scriptFunction.id?.name); + this.enterAnonymousScope(expr.function!); + const res = this.updateScriptFunction(expr.function!, expr.function!.id?.name); this.exitAnonymousScope(); let typeAnnotation: arkts.TypeNode | undefined; @@ -645,8 +645,8 @@ export class FunctionTransformer extends AbstractVisitor { return node; } - this.enterAnonymousScope(value.scriptFunction); - const res = this.updateScriptFunction(value.scriptFunction, value.scriptFunction.id?.name); + this.enterAnonymousScope(value.function!); + const res = this.updateScriptFunction(value.function!, value.function!.id?.name); this.exitAnonymousScope(); this.modified = true; @@ -668,8 +668,8 @@ export class FunctionTransformer extends AbstractVisitor { return node; } - this.enterAnonymousScope(right.scriptFunction); - const res = this.updateScriptFunction(right.scriptFunction, right.scriptFunction.id?.name); + this.enterAnonymousScope(right.function!); + const res = this.updateScriptFunction(right.function!, right.function!.id?.name); this.exitAnonymousScope(); this.modified = true; @@ -691,7 +691,7 @@ export class FunctionTransformer extends AbstractVisitor { return rewriteByType.get(value.type)!(node, metadata); } } - if (arkts.isEtsScript(node) && this.modified) { + if (arkts.isETSModule(node) && this.modified) { factory.createContextTypesImportDeclaration(this.program); } return node; @@ -732,7 +732,7 @@ export class FunctionTransformer extends AbstractVisitor { const thisAttribute = findThisAttribute(node.left!)!; return this.updateThisAttributeAssignment(node, thisAttribute, node.right); } - if (arkts.isEtsScript(node) && this.modified) { + if (arkts.isETSModule(node) && this.modified) { factory.createContextTypesImportDeclaration(this.program); } return node; diff --git a/arkui-plugins/memo-plugins/memo-cache-factory.ts b/arkui-plugins/memo-plugins/memo-cache-factory.ts index 1ca4234ed596b0ebecb6b28d244b19272ebb1d75..4fedcbc2e1f7381bf3e875b6456f418a4bb7ae95 100644 --- a/arkui-plugins/memo-plugins/memo-cache-factory.ts +++ b/arkui-plugins/memo-plugins/memo-cache-factory.ts @@ -143,7 +143,7 @@ export class RewriteFactory { ): arkts.ArrowFunctionExpression { return arkts.factory.updateArrowFunction( node, - RewriteFactory.rewriteScriptFunction(node.scriptFunction, metadata, expectReturn) + RewriteFactory.rewriteScriptFunction(node.function!, metadata, expectReturn) ); } @@ -173,7 +173,7 @@ export class RewriteFactory { const returnType = node.returnTypeAnnotation ?? expectReturn ?? - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID); + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID); const _isVoidReturn = isVoidType(returnType); const scopeDeclaration = factory.createScopeDeclaration( returnType, @@ -256,7 +256,7 @@ export class RewriteFactory { node, node.kind, node.name, - RewriteFactory.rewriteScriptFunction(node.scriptFunction, { + RewriteFactory.rewriteScriptFunction(node.function!, { callName: node.name.name, ...metadata, isSetter, diff --git a/arkui-plugins/memo-plugins/memo-factory.ts b/arkui-plugins/memo-plugins/memo-factory.ts index 948fb082ebea21ea33a76a2652465c111505dada..41b495ded656edb6710015d12b2e20eb58584ebe 100644 --- a/arkui-plugins/memo-plugins/memo-factory.ts +++ b/arkui-plugins/memo-plugins/memo-factory.ts @@ -45,7 +45,7 @@ export class factory { const importDecl: arkts.ETSImportDeclaration = arkts.factory.createImportDeclaration( source, [factory.createContextTypeImportSpecifier(), factory.createIdTypeImportSpecifier()], - arkts.Es2pandaImportKinds.IMPORT_KINDS_TYPE, + arkts.Es2pandaImportKinds.IMPORT_KINDS_TYPES, program!, arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE ); @@ -62,8 +62,8 @@ export class factory { return arkts.factory.createParameterDeclaration( arkts.factory.createIdentifier( RuntimeNames.CONTEXT, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(RuntimeNames.CONTEXT_TYPE)) + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier(RuntimeNames.CONTEXT_TYPE)) ) ), undefined @@ -73,8 +73,8 @@ export class factory { return arkts.factory.createParameterDeclaration( arkts.factory.createIdentifier( RuntimeNames.ID, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(RuntimeNames.ID_TYPE)) + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier(RuntimeNames.ID_TYPE)) ) ), undefined @@ -231,7 +231,7 @@ export class factory { ), returnTypeAnnotation ? [returnTypeAnnotation] - : [arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID)], + : [arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID)], [factory.createIdArgument(hash), arkts.factory.createNumericLiteral(cnt)] ) ), @@ -317,7 +317,7 @@ export class factory { // Compute static createLambdaWrapper(node: arkts.Expression): arkts.ArrowFunctionExpression { - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( arkts.factory.createBlock([arkts.factory.createReturnStatement(node)]), arkts.factory.createFunctionSignature(undefined, [], undefined, false), diff --git a/arkui-plugins/memo-plugins/parameter-transformer.ts b/arkui-plugins/memo-plugins/parameter-transformer.ts index 8aef0822cd3d5292081474db178b415b6a50a612..dbc2ac6fee47c4418ddc70fac049fcce43bb4b91 100644 --- a/arkui-plugins/memo-plugins/parameter-transformer.ts +++ b/arkui-plugins/memo-plugins/parameter-transformer.ts @@ -135,7 +135,7 @@ export class ParameterTransformer extends AbstractVisitor { initializer: arkts.ArrowFunctionExpression, returnType: arkts.TypeNode | undefined ): arkts.ArrowFunctionExpression { - const scriptFunction = initializer.scriptFunction; + const scriptFunction = initializer.function!; if (!scriptFunction.body || !arkts.isBlockStatement(scriptFunction.body)) { return initializer; } diff --git a/arkui-plugins/memo-plugins/return-transformer.ts b/arkui-plugins/memo-plugins/return-transformer.ts index c2c0fac2e6033aca90d5fce9060020b0286a4ebb..2e0108b16e39048f12d23ca13ae175bdfee0aaf8 100644 --- a/arkui-plugins/memo-plugins/return-transformer.ts +++ b/arkui-plugins/memo-plugins/return-transformer.ts @@ -74,7 +74,7 @@ export class ReturnTransformer extends AbstractVisitor { ) { argument = arkts.factory.updateArrowFunction( argument, - factory.updateScriptFunctionWithMemoParameters(argument.scriptFunction) + factory.updateScriptFunctionWithMemoParameters(argument.function!) ); } diff --git a/arkui-plugins/memo-plugins/signature-transformer.ts b/arkui-plugins/memo-plugins/signature-transformer.ts index 6c15cce2ddbb03b30833c632b4b4edeaa8229772..6fc1f07bd0658047c09896d906be9c9ecc1284c1 100644 --- a/arkui-plugins/memo-plugins/signature-transformer.ts +++ b/arkui-plugins/memo-plugins/signature-transformer.ts @@ -75,7 +75,7 @@ export class SignatureTransformer extends AbstractVisitor { node.returnTypeAnnotation ? this.visitor(node.returnTypeAnnotation, shouldApplyMemoToReturnType) : memo - ? arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) + ? arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) : undefined, node.hasReceiver ), diff --git a/arkui-plugins/memo-plugins/utils.ts b/arkui-plugins/memo-plugins/utils.ts index e3b415e7fa2216438caddbf64d73efd2ed1455d7..0954069fc4bcdc32fd45abbd8896e8168ace5494 100644 --- a/arkui-plugins/memo-plugins/utils.ts +++ b/arkui-plugins/memo-plugins/utils.ts @@ -352,9 +352,9 @@ export function isMemoClassProperty(node: arkts.ClassProperty): boolean { export function isMemoMethodDefinition(node: arkts.MethodDefinition): boolean { return ( - hasMemoAnnotation(node.scriptFunction) || - hasMemoIntrinsicAnnotation(node.scriptFunction) || - hasMemoEntryAnnotation(node.scriptFunction) + hasMemoAnnotation(node.function!) || + hasMemoIntrinsicAnnotation(node.function!) || + hasMemoEntryAnnotation(node.function!) ); } @@ -427,18 +427,18 @@ export function isMemoProperty(node: arkts.Property, value: arkts.ArrowFunctionE export function isMemoDeclaredMethod(decl: arkts.MethodDefinition): boolean { if ( decl.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET && - findMemoFromTypeAnnotation(decl.scriptFunction.returnTypeAnnotation) + findMemoFromTypeAnnotation(decl.function!.returnTypeAnnotation) ) { return true; } - return !hasMemoEntryAnnotation(decl.scriptFunction) && isMemoMethodDefinition(decl); + return !hasMemoEntryAnnotation(decl.function!) && isMemoMethodDefinition(decl); } export function isDeclaredMethodWithMemoParams(decl: arkts.MethodDefinition): boolean { if (decl.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET) { return false; } - return decl.scriptFunction.params.some((param) => { + return decl.function!.params.some((param) => { return arkts.isEtsParameterExpression(param) && isMemoETSParameterExpression(param); }); } @@ -616,7 +616,7 @@ export function buildReturnTypeInfo( ): ReturnTypeInfo { const newReturnType = !!returnType ? returnType.clone() - : arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID); + : arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID); return { node: newReturnType, isMemo, diff --git a/arkui-plugins/test/ut/common/annotation.test.ts b/arkui-plugins/test/ut/common/annotation.test.ts index 663454255f56cdc6f457a0ce86e45b7c01be1860..e9f2bf53c7ecc16ab700a972d4a565dd147383a4 100644 --- a/arkui-plugins/test/ut/common/annotation.test.ts +++ b/arkui-plugins/test/ut/common/annotation.test.ts @@ -59,7 +59,7 @@ class AnnotationVisitor extends AbstractVisitor { if (arkts.isEtsParameterExpression(node)) { node.annotations = [this.testAnnotation()]; } else if (arkts.isMethodDefinition(node)) { - node.scriptFunction.setAnnotations([this.testAnnotation()]); + node.function!.setAnnotations([this.testAnnotation()]); node.setOverloads( node.overloads.map((ov) => { if (this.isAnnotationNode(ov)) { @@ -77,7 +77,7 @@ class AnnotationVisitor extends AbstractVisitor { if (arkts.isEtsParameterExpression(node)) { node.annotations = []; } else if (arkts.isMethodDefinition(node)) { - node.scriptFunction.setAnnotations([]); + node.function!.setAnnotations([]); node.setOverloads( node.overloads.map((ov) => { if (this.isAnnotationNode(ov)) { diff --git a/arkui-plugins/ui-plugins/builder-lambda-translators/builder-lambda-transformer.ts b/arkui-plugins/ui-plugins/builder-lambda-translators/builder-lambda-transformer.ts index aba68967cd55f7aa67be5962fa72a91821f137ad..2fe378024514cc41abafd2642090887073f9e898 100644 --- a/arkui-plugins/ui-plugins/builder-lambda-translators/builder-lambda-transformer.ts +++ b/arkui-plugins/ui-plugins/builder-lambda-translators/builder-lambda-transformer.ts @@ -42,7 +42,7 @@ export class BuilderLambdaTransformer extends AbstractVisitor { return this.visitEachChild(lambda); } const node = this.visitEachChild(beforeChildren); - if (arkts.isEtsScript(node) && ImportCollector.getInstance().importInfos.length > 0) { + if (arkts.isETSModule(node) && ImportCollector.getInstance().importInfos.length > 0) { ImportCollector.getInstance().insertCurrentImports(this.program); } return node; diff --git a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts index 9be67b1ddf165a1a545f048ca39f4c462c333a4c..41b7dd779954464427dbbc20ef16032719abbb9c 100644 --- a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts +++ b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts @@ -74,7 +74,7 @@ export class factory { newName: string | undefined, externalSourceName?: string ): arkts.MethodDefinition { - const func: arkts.ScriptFunction = node.scriptFunction; + const func: arkts.ScriptFunction = node.function!; let newParams: arkts.Expression[] = []; if (func.params.length > 0) { newParams.push(...prefixArgs, ...func.params); @@ -86,7 +86,7 @@ export class factory { arkts.FunctionSignature.createFunctionSignature( func.typeParams, newParams, - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ), func.flags, @@ -114,7 +114,7 @@ export class factory { } const argInfo: BuilderLambdaChainingCallArgInfo[] = []; const args = call.arguments; - const params = decl.scriptFunction.params; + const params = decl.function!.params; const isTrailingCall = call.isTrailingCall; forEachArgWithParam( args, @@ -225,14 +225,14 @@ export class factory { arkts.FunctionSignature.createFunctionSignature( undefined, [styleLambdaParam], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC ); - return addMemoAnnotation(arkts.factory.createArrowFunction(func)); + return addMemoAnnotation(arkts.factory.createArrowFunctionExpression(func)); } /* @@ -250,7 +250,7 @@ export class factory { arkts.FunctionSignature.createFunctionSignature( undefined, [styleLambdaParam], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW @@ -275,7 +275,7 @@ export class factory { arg: arkts.ArrowFunctionExpression, hasBuilder?: boolean ): arkts.ArrowFunctionExpression { - const func: arkts.ScriptFunction = arg.scriptFunction; + const func: arkts.ScriptFunction = arg.function!; const updateFunc = arkts.factory.updateScriptFunction( func, !!func.body && arkts.isBlockStatement(func.body) @@ -332,7 +332,7 @@ export class factory { } let isBuilderParam: boolean = false; let isLinkIntrinsic: boolean = false; - decl.scriptFunction.annotations.forEach((anno) => { + decl.function!.annotations.forEach((anno) => { isBuilderParam ||= isDecoratorAnnotation(anno, DecoratorNames.BUILDER_PARAM); isLinkIntrinsic ||= isDecoratorIntrinsicAnnotation(anno, DecoratorIntrinsicNames.LINK); }); @@ -516,7 +516,7 @@ export class factory { * wrap `ConditionScope` or `ConditionBranch` builder function to the block statements. */ static wrapConditionToBlock(statements: readonly arkts.AstNode[], condition: ConditionNames): arkts.AstNode { - const contentArg = arkts.factory.createArrowFunction( + const contentArg = arkts.factory.createArrowFunctionExpression( UIFactory.createScriptFunction({ body: arkts.factory.createBlock(statements), flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, @@ -594,7 +594,7 @@ export class factory { node: arkts.MethodDefinition, externalSourceName?: string ): arkts.MethodDefinition { - const func: arkts.ScriptFunction = node.scriptFunction; + const func: arkts.ScriptFunction = node.function!; const isFunctionCall: boolean = isBuilderLambdaFunctionCall(node); const typeNode: arkts.TypeNode | undefined = builderLambdaMethodDeclType(node); const newOverloads: arkts.MethodDefinition[] = node.overloads.map((method) => @@ -778,8 +778,8 @@ export class factory { static createBindableType(valueType: arkts.TypeNode): arkts.ETSTypeReference { const transformedKey = BindableDecl.BINDABLE; ImportCollector.getInstance().collectImport(transformedKey); - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(transformedKey), arkts.factory.createTSTypeParameterInstantiation([valueType.clone()]) ) @@ -805,7 +805,7 @@ export class factory { arkts.factory.createFunctionSignature( undefined, [], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW @@ -840,11 +840,11 @@ export class factory { static addConditionBuilderDecls(): arkts.MethodDefinition[] { const conditionScope = this.createBuilderWithTrailingLambdaDecl( ConditionNames.CONDITION_SCOPE, - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) ); const conditionBranch = this.createBuilderWithTrailingLambdaDecl( ConditionNames.CONDITION_BRANCH, - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID) ); return [conditionScope, conditionBranch]; } diff --git a/arkui-plugins/ui-plugins/builder-lambda-translators/utils.ts b/arkui-plugins/ui-plugins/builder-lambda-translators/utils.ts index 9ccc36a1ccbafae6670096c81a7a703a64e13a7e..dc6f83b7b5059352b404a334a6972757df6efac5 100644 --- a/arkui-plugins/ui-plugins/builder-lambda-translators/utils.ts +++ b/arkui-plugins/ui-plugins/builder-lambda-translators/utils.ts @@ -108,8 +108,8 @@ export function isBuilderLambda(node: arkts.AstNode, nodeDecl?: arkts.AstNode | * @param node method definition node */ export function isFunctionWithReceiver(node: arkts.MethodDefinition): boolean { - if (node.scriptFunction && arkts.isScriptFunction(node.scriptFunction)) { - return node.scriptFunction.hasReceiver; + if (node.function! && arkts.isScriptFunction(node.function!)) { + return node.function!.hasReceiver; } return false; } @@ -178,8 +178,8 @@ export function getDeclForBuilderLambdaMethodDecl(node: arkts.AstNode): arkts.As const isBuilderLambda: boolean = !!node.name && isBuilderLambdaCall(node.name); const isMethodDecl: boolean = - !!node.scriptFunction && - arkts.hasModifierFlag(node.scriptFunction, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE); + !!node.function! && + arkts.hasModifierFlag(node.function!, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE); if (isBuilderLambda && isMethodDecl) { return node; } @@ -245,7 +245,7 @@ export function isBuilderLambdaCall( return isBuilderLambdaMethod(decl); } if (arkts.isFunctionExpression(decl)) { - return hasBuilderLambdaAnnotation(decl.scriptFunction); + return hasBuilderLambdaAnnotation(decl.function!); } return false; } @@ -255,7 +255,7 @@ export function isBuilderLambdaMethod(node: arkts.MethodDefinition): boolean { return false; } - const result = hasBuilderLambdaAnnotation(node.scriptFunction); + const result = hasBuilderLambdaAnnotation(node.function!); if (result) { return true; } @@ -283,7 +283,7 @@ export function findBuilderLambdaInMethod(node: arkts.MethodDefinition): arkts.A if (!node || !arkts.isMethodDefinition(node)) { return undefined; } - const result = findBuilderLambdaAnnotation(node.scriptFunction); + const result = findBuilderLambdaAnnotation(node.function!); if (!!result) { return result; } @@ -308,7 +308,7 @@ export function findBuilderLambdaInCall( return findBuilderLambdaInMethod(decl); } if (arkts.isFunctionExpression(decl)) { - return findBuilderLambdaAnnotation(decl.scriptFunction); + return findBuilderLambdaAnnotation(decl.function!); } return undefined; } @@ -352,8 +352,8 @@ export function findBuilderLambdaDeclInfo(decl: arkts.AstNode | undefined): Buil return undefined; } if (arkts.isMethodDefinition(decl)) { - const params = decl.scriptFunction.params.map((p) => p.clone()); - const returnType = decl.scriptFunction.returnTypeAnnotation?.clone(); + const params = decl.function!.params.map((p) => p.clone()); + const returnType = decl.function!.returnTypeAnnotation?.clone(); const isFunctionCall = isBuilderLambdaFunctionCall(decl); return { isFunctionCall, params, returnType, moduleName }; } @@ -391,10 +391,10 @@ export function isSafeType(type: arkts.TypeNode | undefined): boolean { } export function builderLambdaMethodDeclType(method: arkts.MethodDefinition): arkts.TypeNode | undefined { - if (!method || !method.scriptFunction) { + if (!method || !method.function!) { return undefined; } - return method.scriptFunction.returnTypeAnnotation; + return method.function!.returnTypeAnnotation; } export function builderLambdaType(leaf: arkts.CallExpression): arkts.Identifier | undefined { diff --git a/arkui-plugins/ui-plugins/checked-transformer.ts b/arkui-plugins/ui-plugins/checked-transformer.ts index 8fe41f30c05dbeb4d2cc58ef523cc2f0673d8243..fa703fd164c85e573d725be1fc9548b4eb114014 100644 --- a/arkui-plugins/ui-plugins/checked-transformer.ts +++ b/arkui-plugins/ui-plugins/checked-transformer.ts @@ -96,7 +96,7 @@ export class CheckedTransformer extends AbstractVisitor { } } if (arkts.isMethodDefinition(node) && this.scope.customComponents.length > 0) { - const name = node.name.name; + const name = node.id!.name; const scopeInfo = this.scope.customComponents.pop()!; scopeInfo.hasInitializeStruct ||= name === CustomComponentNames.COMPONENT_INITIALIZE_STRUCT; scopeInfo.hasUpdateStruct ||= name === CustomComponentNames.COMPONENT_UPDATE_STRUCT; @@ -126,7 +126,7 @@ export class CheckedTransformer extends AbstractVisitor { let isFrom1_1 = false; if (arkts.isMethodDefinition(decl)) { - const annotations = decl.scriptFunction.annotations; + const annotations = decl.function!.annotations; const decorators: string[] = annotations.map(annotation => { return (annotation.expr as arkts.Identifier).name; }); @@ -148,11 +148,11 @@ export class CheckedTransformer extends AbstractVisitor { visitor(beforeChildren: arkts.AstNode): arkts.AstNode { this.enter(beforeChildren); if (arkts.isCallExpression(beforeChildren)) { - const decl = arkts.getDecl(beforeChildren.expression); - if (arkts.isIdentifier(beforeChildren.expression) && this.isFromBuilder1_1(decl)) { + const decl = arkts.getDecl(beforeChildren.callee!); + if (arkts.isIdentifier(beforeChildren.callee!) && this.isFromBuilder1_1(decl)) { // Builder this.addcompatibleComponentImport(); - return generateBuilderCompatible(beforeChildren, beforeChildren.expression.name); + return generateBuilderCompatible(beforeChildren, beforeChildren.callee!.name); } else if (isBuilderLambda(beforeChildren, decl)) { const lambda = builderLambdaFactory.transformBuilderLambda(beforeChildren); return this.visitEachChild(lambda); @@ -196,7 +196,7 @@ export class CheckedTransformer extends AbstractVisitor { return structFactory.transformCustomDialogController(node); } - if (arkts.isEtsScript(node) && ImportCollector.getInstance().importInfos.length > 0) { + if (arkts.isETSModule(node) && ImportCollector.getInstance().importInfos.length > 0) { ImportCollector.getInstance().insertCurrentImports(this.program); LogCollector.getInstance().shouldIgnoreError(this.projectConfig?.ignoreError); LogCollector.getInstance().emitLogInfo(); diff --git a/arkui-plugins/ui-plugins/component-transformer.ts b/arkui-plugins/ui-plugins/component-transformer.ts index a4c436972cfdb33ca6422c8112069ea3f6e933a7..8dd34e8f4a01e004a3249468eaf730bb505842a1 100644 --- a/arkui-plugins/ui-plugins/component-transformer.ts +++ b/arkui-plugins/ui-plugins/component-transformer.ts @@ -14,9 +14,6 @@ */ import * as arkts from '@koalaui/libarkts'; -import { getInteropPath } from '../path'; -const interop = require(getInteropPath()); -const nullptr = interop.nullptr; import { AbstractVisitor, VisitorOptions } from '../common/abstract-visitor'; import { CustomComponentNames, @@ -127,7 +124,7 @@ export class ComponentTransformer extends AbstractVisitor { } enter(node: arkts.AstNode) { - if (arkts.isStructDeclaration(node) && !!node.definition.ident) { + if (arkts.isETSStructDeclaration(node) && !!node.definition?.ident) { const info: ScopeInfo | undefined = collectCustomComponentScopeInfo(node); if (info) { this.scopeInfos.push(info); @@ -178,7 +175,7 @@ export class ComponentTransformer extends AbstractVisitor { } exit(node: arkts.AstNode) { - if (arkts.isStructDeclaration(node) || arkts.isClassDeclaration(node)) { + if (arkts.isETSStructDeclaration(node) || arkts.isClassDeclaration(node)) { if (!node.definition || !node.definition.ident || this.scopeInfos.length === 0) return; if (this.scopeInfos[this.scopeInfos.length - 1]?.name === node.definition.ident.name) { this.scopeInfos.pop(); @@ -187,7 +184,7 @@ export class ComponentTransformer extends AbstractVisitor { } createImportDeclaration(sourceName: string, importedName: string): void { - const source: arkts.StringLiteral = arkts.factory.create1StringLiteral(sourceName); + const source: arkts.StringLiteral = arkts.factory.createStringLiteral(sourceName); const imported: arkts.Identifier = arkts.factory.createIdentifier(importedName); // Insert this import at the top of the script's statements. if (!this.program) { @@ -197,21 +194,21 @@ export class ComponentTransformer extends AbstractVisitor { source, imported, imported, - arkts.Es2pandaImportKinds.IMPORT_KINDS_VALUE, + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL, this.program ); } - processEtsScript(node: arkts.EtsScript): arkts.EtsScript { + processEtsScript(node: arkts.ETSModule): arkts.ETSModule { if (this.isExternal && this.externalSourceName === ENTRY_POINT_IMPORT_SOURCE_NAME) { const navInterface = entryFactory.createNavInterface(); navInterface.modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT; - return arkts.factory.updateEtsScript(node, [...node.statements, navInterface]); + return arkts.factory.updateETSModule(node, [...node.statements, navInterface], node.ident, node.getNamespaceFlag()); } if (this.isExternal && this.componentInterfaceCollection.length === 0 && this.entryNames.length === 0) { return node; } - const updateStatements: arkts.AstNode[] = []; + const updateStatements: arkts.Statement[] = []; if (this.shouldAddLinkIntrinsic) { const expr = arkts.factory.createIdentifier(DecoratorIntrinsicNames.LINK); updateStatements.push(factory.createIntrinsicAnnotationDeclaration({ expr })); @@ -229,12 +226,12 @@ export class ComponentTransformer extends AbstractVisitor { this.createImportDeclaration(CUSTOM_COMPONENT_IMPORT_SOURCE_NAME, CustomComponentNames.PAGE_LIFE_CYCLE); updateStatements.push(...this.entryNames.map(entryFactory.generateEntryWrapper)); updateStatements.push( - entryFactory.callRegisterNamedRouter(this.entryRouteName, this.projectConfig, this.program?.absName) + entryFactory.callRegisterNamedRouter(this.entryRouteName, this.projectConfig, this.program?.absoluteName) ); this.createImportDeclaration(ENTRY_POINT_IMPORT_SOURCE_NAME, NavigationNames.NAVINTERFACE); } if (updateStatements.length > 0) { - return arkts.factory.updateEtsScript(node, [...node.statements, ...updateStatements]); + return arkts.factory.updateETSModule(node, [...node.statements, ...updateStatements], node.ident, node.getNamespaceFlag()); } return node; } @@ -290,15 +287,15 @@ export class ComponentTransformer extends AbstractVisitor { arkts.classDefinitionFlags(definition) | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC; - const body = isDecl ? undefined : arkts.factory.createBlock([arkts.factory.createReturnStatement()]); - const param: arkts.ETSParameterExpression = arkts.factory.createParameterDeclaration( + const body = isDecl ? undefined : arkts.factory.createBlockStatement([arkts.factory.createReturnStatement()]); + const param: arkts.ETSParameterExpression = arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( CustomComponentNames.OPTIONS, factory.createTypeReferenceFromString(getCustomComponentOptionsName(definition.ident!.name)) ), - undefined + false ); - const returnTypeAnnotation = arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID); + const returnTypeAnnotation = arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID); const flags = arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD; const kind = arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD; const key = arkts.factory.createIdentifier(CustomComponentNames.BUILDCOMPATIBLENODE); @@ -319,14 +316,14 @@ export class ComponentTransformer extends AbstractVisitor { } processComponent( - node: arkts.ClassDeclaration | arkts.StructDeclaration - ): arkts.ClassDeclaration | arkts.StructDeclaration { + node: arkts.ClassDeclaration | arkts.ETSStructDeclaration + ): arkts.ClassDeclaration | arkts.ETSStructDeclaration { const scopeInfo = this.scopeInfos[this.scopeInfos.length - 1]; const className = node.definition?.ident?.name; if (!className || scopeInfo?.name !== className) { return node; } - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { this.collectComponentMembers(node, className); } const customComponentInterface = this.generateComponentInterface( @@ -352,8 +349,8 @@ export class ComponentTransformer extends AbstractVisitor { newDefinitionBody ); - if (arkts.isStructDeclaration(node)) { - arkts.classDefinitionSetFromStructModifier(newDefinition); + if (arkts.isETSStructDeclaration(node)) { + newDefinition.setFromStructModifier() const _node = arkts.factory.createClassDeclaration(newDefinition); _node.modifiers = node.modifiers; _node.startPosition = node.startPosition; @@ -365,7 +362,7 @@ export class ComponentTransformer extends AbstractVisitor { } createNewDefinition( - node: arkts.ClassDeclaration | arkts.StructDeclaration, + node: arkts.ClassDeclaration | arkts.ETSStructDeclaration, className: string, definition: arkts.ClassDefinition, newDefinitionBody: arkts.AstNode[] @@ -389,8 +386,8 @@ export class ComponentTransformer extends AbstractVisitor { undefined, // superTypeParams doen't work [...definition.implements, ...factory.generateImplementsForStruct(scopeInfo.annotations)], undefined, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(extendsName), arkts.factory.createTSTypeParameterInstantiation([ factory.createTypeReferenceFromString(className), @@ -422,8 +419,8 @@ export class ComponentTransformer extends AbstractVisitor { .createInterfaceDeclaration( [], arkts.factory.createIdentifier(getCustomComponentOptionsName(name)), - nullptr, - arkts.factory.createInterfaceBody([...(this.structMembersMap.get(name) || [])]), + undefined, + arkts.factory.createTSInterfaceBody([...(this.structMembersMap.get(name) || [])]), false, false ) @@ -432,10 +429,10 @@ export class ComponentTransformer extends AbstractVisitor { return interfaceNode; } - collectComponentMembers(node: arkts.StructDeclaration, className: string): void { + collectComponentMembers(node: arkts.ETSStructDeclaration, className: string): void { const members = filterDefined( collect( - ...node.definition.body.filter(arkts.isClassProperty).map((it) => { + ...node.definition!.body.filter(arkts.isClassProperty).map((it) => { if (hasDecoratorName(it, DecoratorNames.PROVIDE)) { factory.processNoAliasProvideVariable(it); } @@ -508,13 +505,13 @@ export class ComponentTransformer extends AbstractVisitor { } processInteropCall(node: arkts.CallExpression): arkts.CallExpression { - const ident = node.expression; - if (!(ident instanceof arkts.Identifier)) { + const ident = node.callee; + if (!arkts.isIdentifier(ident)) { return node; } const className = ident.name; const trailingBlock = node.trailingBlock; - const content = trailingBlock ? arkts.factory.createArrowFunction( + const content = trailingBlock ? arkts.factory.createArrowFunctionExpression( factory.createScriptFunction({ body: trailingBlock, flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, @@ -527,7 +524,7 @@ export class ComponentTransformer extends AbstractVisitor { const context: InteropContext = { className: className, path: path, - arguments: args && args.length === 1 && args[0] instanceof arkts.ObjectExpression ? args[0] : undefined, + arguments: args && args.length === 1 && arkts.isObjectExpression(args[0]) ? args[0] : undefined, content: content }; return generateInstantiateInterop(context); @@ -538,11 +535,11 @@ export class ComponentTransformer extends AbstractVisitor { visitor(node: arkts.AstNode): arkts.AstNode { this.enter(node); const newNode = this.visitEachChild(node); - if (arkts.isEtsScript(newNode)) { + if (arkts.isETSModule(newNode)) { return this.processEtsScript(newNode); } if ( - arkts.isStructDeclaration(newNode) && + arkts.isETSStructDeclaration(newNode) && this.scopeInfos.length > 0 && isComponentStruct(newNode, this.scopeInfos[this.scopeInfos.length - 1]) ) { diff --git a/arkui-plugins/ui-plugins/entry-translators/factory.ts b/arkui-plugins/ui-plugins/entry-translators/factory.ts index e4dd29d224a73bb929913285ac9d5fb2cb602a91..42857a74cb9a3eb4480bda4daa04d815e2502ea4 100644 --- a/arkui-plugins/ui-plugins/entry-translators/factory.ts +++ b/arkui-plugins/ui-plugins/entry-translators/factory.ts @@ -94,7 +94,7 @@ export class factory { arkts.FunctionSignature.createFunctionSignature( undefined, [], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, @@ -152,7 +152,7 @@ export class factory { const signature: arkts.FunctionSignature = arkts.FunctionSignature.createFunctionSignature( undefined, [], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ); const entryScript: arkts.ScriptFunction = arkts.factory @@ -166,7 +166,7 @@ export class factory { const def = arkts.factory.createClassProperty( key, - arkts.factory.createArrowFunction(entryScript), + arkts.factory.createArrowFunctionExpression(entryScript), arkts.factory.createFunctionType(signature, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, false @@ -190,8 +190,8 @@ export class factory { undefined, [], undefined, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(EntryWrapperNames.ENTRY_POINT_CLASS_NAME) ) ), @@ -216,10 +216,10 @@ export class factory { node.definition?.body.forEach((member) => { if ( arkts.isMethodDefinition(member) && - !!member.scriptFunction.id && - member.scriptFunction.id.name === EntryWrapperNames.ENTRY_FUNC + !!member.function!.id && + member.function!.id.name === EntryWrapperNames.ENTRY_FUNC ) { - addMemoAnnotation(member.scriptFunction); + addMemoAnnotation(member.function!); arkts.NodeCache.getInstance().collect(member); } }); @@ -320,9 +320,9 @@ export class factory { storageArg, ]) ); - if (ctor.scriptFunction.body && arkts.isBlockStatement(ctor.scriptFunction.body)) { - ctor.scriptFunction.setBody( - arkts.factory.updateBlock(ctor.scriptFunction.body, [...ctor.scriptFunction.body.statements, superCall]) + if (ctor.function!.body && arkts.isBlockStatement(ctor.function!.body)) { + ctor.function!.setBody( + arkts.factory.updateBlock(ctor.function!.body, [...ctor.function!.body.statements, superCall]) ); } } @@ -351,7 +351,7 @@ export class factory { ], false ), - uiFactory.createTypeReferenceFromString(NavigationNames.NAVINTERFACE), + uifactory.createTypeReferenceFromString(NavigationNames.NAVINTERFACE), false ); } @@ -387,8 +387,8 @@ export class factory { [ arkts.factory.createStringLiteral(entryRouteName ?? ''), arkts.factory.createETSNewClassInstanceExpression( - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(EntryWrapperNames.WRAPPER_CLASS_NAME) ) ), @@ -427,7 +427,7 @@ export class factory { return arkts.factory.createClassProperty( arkts.factory.createIdentifier(propName), undefined, - uiFactory.createTypeReferenceFromString('string'), + uifactory.createTypeReferenceFromString('string'), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, false ); @@ -438,7 +438,7 @@ export class factory { */ static registerRouteParam(name: EntryWrapperNames, type: string): arkts.ETSParameterExpression { return arkts.factory.createParameterDeclaration( - arkts.factory.createIdentifier(name, uiFactory.createTypeReferenceFromString(type)), + arkts.factory.createIdentifier(name, uifactory.createTypeReferenceFromString(type)), undefined ); } diff --git a/arkui-plugins/ui-plugins/index.ts b/arkui-plugins/ui-plugins/index.ts index 1785e4854352aa9d54977fe12a7ed1909928947e..1d25b7633815dccf93c2b1fe248aa16304e7f6e5 100644 --- a/arkui-plugins/ui-plugins/index.ts +++ b/arkui-plugins/ui-plugins/index.ts @@ -32,8 +32,7 @@ export function uiTransform(): Plugins { }; } -function parsedTransform(this: PluginContext): arkts.EtsScript | undefined { - let script: arkts.EtsScript | undefined; +function parsedTransform(this: PluginContext): arkts.ETSModule | undefined { console.log('[UI PLUGIN] AFTER PARSED ENTER'); arkts.Performance.getInstance().memoryTrackerPrintCurrent('ArkTS:Parse'); arkts.Performance.getInstance().memoryTrackerReset(); @@ -41,7 +40,7 @@ function parsedTransform(this: PluginContext): arkts.EtsScript | undefined { const contextPtr = this.getContextPtr() ?? arkts.arktsGlobal.compilerContext?.peer; if (!!contextPtr) { let program = arkts.getOrUpdateGlobalContext(contextPtr).program; - script = program.astNode; + let script = program.ast; const cachePath: string | undefined = this.getProjectConfig()?.cachePath; const canSkipPhases = program.canSkipPhases(); debugLog('[BEFORE PARSED SCRIPT] script: ', script.dumpSrc()); @@ -54,7 +53,7 @@ function parsedTransform(this: PluginContext): arkts.EtsScript | undefined { ); arkts.Performance.getInstance().createEvent('ui-parsed'); program = parsedProgramVisit(program, this, canSkipPhases); - script = program.astNode; + script = program.ast; arkts.Performance.getInstance().stopEvent('ui-parsed', true); debugLog('[AFTER PARSED SCRIPT] script: ', script.dumpSrc()); debugDump( @@ -64,15 +63,15 @@ function parsedTransform(this: PluginContext): arkts.EtsScript | undefined { cachePath, program.fileNameWithExtension ); - this.setArkTSAst(script); + this.setArkTSAst(script as arkts.ETSModule); arkts.Performance.getInstance().memoryTrackerGetDelta('UIPlugin:AfterParse'); arkts.Performance.getInstance().memoryTrackerReset(); arkts.Performance.getInstance().stopMemRecord('Node:UIPlugin:AfterParse'); console.log('[UI PLUGIN] AFTER PARSED EXIT'); - return script; + return script as arkts.ETSModule; } console.log('[UI PLUGIN] AFTER PARSED EXIT WITH NO TRANSFORM'); - return script; + return undefined; } function parsedProgramVisit( @@ -99,8 +98,7 @@ function parsedProgramVisit( return program; } -function checkedTransform(this: PluginContext): arkts.EtsScript | undefined { - let script: arkts.EtsScript | undefined; +function checkedTransform(this: PluginContext): arkts.ETSModule | undefined { console.log('[UI PLUGIN] AFTER CHECKED ENTER'); arkts.Performance.getInstance().memoryTrackerPrintCurrent('ArkTS:Check'); arkts.Performance.getInstance().memoryTrackerGetDelta('ArkTS:Check'); @@ -109,7 +107,7 @@ function checkedTransform(this: PluginContext): arkts.EtsScript | undefined { const contextPtr = this.getContextPtr() ?? arkts.arktsGlobal.compilerContext?.peer; if (!!contextPtr) { let program = arkts.getOrUpdateGlobalContext(contextPtr).program; - script = program.astNode; + let script = program.ast; const cachePath: string | undefined = this.getProjectConfig()?.cachePath; const canSkipPhases = program.canSkipPhases(); debugLog('[BEFORE STRUCT SCRIPT] script: ', script.dumpSrc()); @@ -122,7 +120,7 @@ function checkedTransform(this: PluginContext): arkts.EtsScript | undefined { ); arkts.Performance.getInstance().createEvent('ui-checked'); program = checkedProgramVisit(program, this, canSkipPhases); - script = program.astNode; + script = program.ast; arkts.Performance.getInstance().stopEvent('ui-checked', true); debugLog('[AFTER STRUCT SCRIPT] script: ', script.dumpSrc()); debugDump( @@ -132,14 +130,14 @@ function checkedTransform(this: PluginContext): arkts.EtsScript | undefined { cachePath, program.fileNameWithExtension ); - this.setArkTSAst(script); + this.setArkTSAst(script as arkts.ETSModule); arkts.Performance.getInstance().memoryTrackerGetDelta('UIPlugin:UI-AfterCheck'); arkts.Performance.getInstance().stopMemRecord('Node:UIPlugin:UI-AfterCheck'); console.log('[UI PLUGIN] AFTER CHECKED EXIT'); - return script; + return script as arkts.ETSModule; } console.log('[UI PLUGIN] AFTER CHECKED EXIT WITH NO TRANSFORM'); - return script; + return undefined; } function checkedProgramVisit( diff --git a/arkui-plugins/ui-plugins/interop/builder-interop.ts b/arkui-plugins/ui-plugins/interop/builder-interop.ts index f2073b52d206698b503f71095287983f1f87a4df..845e190588d05207e41e69fb3e3c934d4c46e2da 100644 --- a/arkui-plugins/ui-plugins/interop/builder-interop.ts +++ b/arkui-plugins/ui-plugins/interop/builder-interop.ts @@ -32,7 +32,6 @@ interface builderParam { function invokeFunctionWithParam(functionName: string, result: string, className: string, args: arkts.AstNode[]): arkts.Statement { return arkts.factory.createVariableDeclaration( - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET, [arkts.factory.createVariableDeclarator( arkts.Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_LET, @@ -104,7 +103,7 @@ function createBuilderInitializer(className: string, functionName: string, param createInitReturn(className) ] ); - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( block, arkts.factory.createFunctionSignature( @@ -145,8 +144,8 @@ function getInstanceParam(): arkts.Statement { arkts.factory.createStringLiteral('arg1') ] ), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(ESValueMethodNames.ESVALUE) ) ), @@ -303,8 +302,8 @@ function getParamWrappedProperty(): arkts.Statement { false ), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(ESValueMethodNames.ESVALUE) ) ), @@ -334,8 +333,8 @@ function setInstanceParam(): arkts.Statement { false, false ), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(ESValueMethodNames.ESVALUE) ) ), @@ -421,7 +420,7 @@ function getUpdateArgs(node: arkts.CallExpression): arkts.Statement[] { } function createBuilderUpdate(node: arkts.CallExpression): arkts.ArrowFunctionExpression { - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( arkts.factory.createBlock( [ @@ -433,8 +432,8 @@ function createBuilderUpdate(node: arkts.CallExpression): arkts.ArrowFunctionExp [ arkts.factory.createParameterDeclaration( arkts.factory.createIdentifier(InteroperAbilityNames.INSTANCE, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(ESValueMethodNames.ESVALUE) ) ) diff --git a/arkui-plugins/ui-plugins/interop/interop.ts b/arkui-plugins/ui-plugins/interop/interop.ts index 8da4bc6d59e6567f8d924e9ead065ab5a57c86dc..f8a1799f4d3d825f90f0da9f96554b8c7f0d361c 100644 --- a/arkui-plugins/ui-plugins/interop/interop.ts +++ b/arkui-plugins/ui-plugins/interop/interop.ts @@ -45,7 +45,7 @@ function paramsLambdaDeclaration(name: string, args?: arkts.ObjectExpression): a arkts.factory.createVariableDeclarator( arkts.Es2pandaVariableDeclaratorFlag.VARIABLE_DECLARATOR_FLAG_LET, arkts.factory.createIdentifier(InteroperAbilityNames.PARAMSLAMBDA), - arkts.factory.createArrowFunction( + arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( arkts.factory.createBlock([arkts.factory.createReturnStatement( args ? args : arkts.ObjectExpression.createObjectExpression( @@ -57,8 +57,8 @@ function paramsLambdaDeclaration(name: string, args?: arkts.ObjectExpression): a arkts.factory.createFunctionSignature( undefined, [], - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(getCustomComponentOptionsName(name)) ) ), @@ -103,8 +103,8 @@ function generateTSASExpression(expression: arkts.AstNode): arkts.Expression { undefined, undefined ), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Object') ) ), @@ -124,7 +124,7 @@ function newComponent(className: string): arkts.Statement { arkts.factory.createUndefinedLiteral(), generateTSASExpression(arkts.factory.createIdentifier(InteroperAbilityNames.ELMTID)), arkts.factory.createTSAsExpression( - arkts.factory.createArrowFunction( + arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( arkts.factory.createBlock([]), arkts.factory.createFunctionSignature( @@ -137,8 +137,8 @@ function newComponent(className: string): arkts.Statement { arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, ) ), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Object') ) ), @@ -202,7 +202,7 @@ function createWrapperBlock(context: InteropContext, varMap: Map, updateProp: arkts.Property[]): arkts.ArrowFunctionExpression { const block = createWrapperBlock(context, varMap, updateProp); - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( block, arkts.factory.createFunctionSignature( @@ -259,7 +259,7 @@ function updateStateVars(updateProp: arkts.Property[]): arkts.Statement[] { */ function createUpdater(updateProp: arkts.Property[]): arkts.ArrowFunctionExpression { const updateState = (updateProp.length !== 0) ? updateStateVars(updateProp) : []; - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( arkts.factory.createBlock( [ @@ -271,8 +271,8 @@ function createUpdater(updateProp: arkts.Property[]): arkts.ArrowFunctionExpress [ arkts.factory.createParameterDeclaration( arkts.factory.createIdentifier(InteroperAbilityNames.INSTANCE, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(ESValueMethodNames.ESVALUE) ) ) @@ -299,8 +299,8 @@ function updateArguments(context: InteropContext, name: string): arkts.ObjectExp arkts.factory.createIdentifier(name), arkts.factory.createTSAsExpression( context.content, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Function') ) ), @@ -316,8 +316,8 @@ function updateArguments(context: InteropContext, name: string): arkts.ObjectExp arkts.factory.createIdentifier(name), arkts.factory.createTSAsExpression( context.content, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Function') ) ), diff --git a/arkui-plugins/ui-plugins/interop/legacy-transformer.ts b/arkui-plugins/ui-plugins/interop/legacy-transformer.ts index 366678e19cbfc237fbe16c1b30076df1975bba9b..e0d3c3d36ca477749ba6e8893f034b79de2047e6 100644 --- a/arkui-plugins/ui-plugins/interop/legacy-transformer.ts +++ b/arkui-plugins/ui-plugins/interop/legacy-transformer.ts @@ -62,8 +62,8 @@ export class LegacyTransformer extends AbstractVisitor { return arkts.factory.createParameterDeclaration( arkts.factory.createIdentifier( name, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(type) ) ) @@ -88,7 +88,7 @@ export class LegacyTransformer extends AbstractVisitor { arkts.FunctionSignature.createFunctionSignature( undefined, [path, line, col, options, trailingBlock], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, @@ -136,7 +136,7 @@ export class LegacyTransformer extends AbstractVisitor { return interfaceNode; } - processComponent(node: arkts.StructDeclaration): arkts.StructDeclaration | arkts.ClassDeclaration { + processComponent(node: arkts.ETSStructDeclaration): arkts.ETSStructDeclaration | arkts.ClassDeclaration { const definition: arkts.ClassDefinition = node.definition!; const ident = definition.ident!; const hasExportFlag = @@ -161,7 +161,7 @@ export class LegacyTransformer extends AbstractVisitor { arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE ); - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { const _node = arkts.factory.createClassDeclaration(newDefinition); _node.modifiers = node.modifiers; return _node; @@ -172,8 +172,8 @@ export class LegacyTransformer extends AbstractVisitor { processConstructor(node: arkts.MethodDefinition): arkts.MethodDefinition { const valueType = arkts.factory.createUnionType([ - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Object') ) ), @@ -220,7 +220,7 @@ export class LegacyTransformer extends AbstractVisitor { ); } - collectComponentMembers(node: arkts.StructDeclaration, className: string): Map { + collectComponentMembers(node: arkts.ETSStructDeclaration, className: string): Map { const result: Map = new Map(); node.definition.body.map((it) => { if (arkts.isClassProperty(it)) { @@ -244,14 +244,14 @@ export class LegacyTransformer extends AbstractVisitor { } enter(node: arkts.AstNode): void { - if (arkts.isStructDeclaration(node) && !!node.definition.ident) { + if (arkts.isETSStructDeclaration(node) && !!node.definition.ident) { const scopeInfo: ScopeInfo = { name: node.definition.ident.name }; this.scopeInfos.push(scopeInfo); } } exit(node: arkts.AstNode): void { - if (arkts.isStructDeclaration(node) || arkts.isClassDeclaration(node)) { + if (arkts.isETSStructDeclaration(node) || arkts.isClassDeclaration(node)) { if (!node.definition || !node.definition.ident || this.scopeInfos.length === 0) { return; } @@ -264,8 +264,8 @@ export class LegacyTransformer extends AbstractVisitor { handleWrappedBuilderNode(node: arkts.ETSTypeReference): arkts.ETSTypeReference { if (node.part && arkts.isETSTypeReferencePart(node.part) && node.part.name && arkts.isIdentifier(node.part.name) && node.part.name.name === 'WrappedBuilder') { - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Any') ) ); @@ -314,17 +314,17 @@ export class LegacyTransformer extends AbstractVisitor { visitor(node: arkts.AstNode): arkts.AstNode { this.enter(node); const newNode = this.visitEachChild(node); - if (arkts.isEtsScript(newNode)) { + if (arkts.isETSModule(newNode)) { return this.processEtsScript(newNode); } - if (arkts.isStructDeclaration(newNode)) { + if (arkts.isETSStructDeclaration(newNode)) { const definition = newNode.definition!; const annotations = definition.annotations; if (annotations.some(annotation => annotation instanceof arkts.Identifier && annotation.name === 'Component')) { return newNode; } const className = newNode.definition?.ident?.name!; - const memberMap = this.collectComponentMembers(newNode as arkts.StructDeclaration, className); + const memberMap = this.collectComponentMembers(newNode as arkts.ETSStructDeclaration, className); this.componentInterfaceCollection.push(this.generateComponentInterface(className, node.modifiers, memberMap)); const updateNode = this.processComponent(newNode); this.exit(newNode); diff --git a/arkui-plugins/ui-plugins/name-collector.ts b/arkui-plugins/ui-plugins/name-collector.ts index 60d29a3e06e15f48b93298d1aa4b34dde0bc902a..2a2babf0626a6ecf295de2c19767b066942500fe 100644 --- a/arkui-plugins/ui-plugins/name-collector.ts +++ b/arkui-plugins/ui-plugins/name-collector.ts @@ -69,9 +69,9 @@ export class NameCollector extends AbstractVisitor { const isComponentBuilder = hasBuilderLambdaAnnotation(node); if (!isComponentBuilder) return undefined; - if (!node.scriptFunction.id) return undefined; + if (!node.function?.id) return undefined; - return node.scriptFunction; + return node.function; } visitor(node: arkts.AstNode): arkts.AstNode { diff --git a/arkui-plugins/ui-plugins/printer-transformer.ts b/arkui-plugins/ui-plugins/printer-transformer.ts index 2ccab0b0ee73c012f40da268ffb6e7398c58b7b8..91d04bb142882b299b28d9769d74398b0b12b2e2 100644 --- a/arkui-plugins/ui-plugins/printer-transformer.ts +++ b/arkui-plugins/ui-plugins/printer-transformer.ts @@ -21,7 +21,7 @@ export interface TransformerOptions { } export default function printerTransformer(userPluginOptions?: TransformerOptions) { - return (node: arkts.EtsScript) => { + return (node: arkts.ETSModule) => { return new PrintVisitor().visitor(node); }; } diff --git a/arkui-plugins/ui-plugins/property-translators/builderParam.ts b/arkui-plugins/ui-plugins/property-translators/builderParam.ts index 41c616f607c7c69f403d5c3db8862a4f7a5e67b8..824f405652d5369b7ddb0b70d676eb92968efd2e 100644 --- a/arkui-plugins/ui-plugins/property-translators/builderParam.ts +++ b/arkui-plugins/ui-plugins/property-translators/builderParam.ts @@ -130,7 +130,7 @@ export class BuilderParamInterfaceTranslator e */ private updateBuilderParamMethodInInterface(method: arkts.MethodDefinition): arkts.MethodDefinition { if (method.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET) { - const type: arkts.TypeNode | undefined = method.scriptFunction.returnTypeAnnotation; + const type: arkts.TypeNode | undefined = method.function!.returnTypeAnnotation; if (!!type && (arkts.isETSFunctionType(type) || arkts.isETSUnionType(type))) { addMemoAnnotation(type); } @@ -144,7 +144,7 @@ export class BuilderParamInterfaceTranslator e removeDecorator(method, DecoratorNames.BUILDER_PARAM); arkts.NodeCache.getInstance().collect(method, { isGetter: true }); } else if (method.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET) { - const param = method.scriptFunction.params.at(0)! as arkts.ETSParameterExpression; + const param = method.function!.params.at(0)! as arkts.ETSParameterExpression; const type = param.type; if (!!type && (arkts.isETSFunctionType(type) || arkts.isETSUnionType(type))) { addMemoAnnotation(type); diff --git a/arkui-plugins/ui-plugins/property-translators/computed.ts b/arkui-plugins/ui-plugins/property-translators/computed.ts index 82daf847d2b2442ed57053ed0641c67ded719a28..1afb01d35b6f9b6af3e9342adc358fd628d96cf9 100644 --- a/arkui-plugins/ui-plugins/property-translators/computed.ts +++ b/arkui-plugins/ui-plugins/property-translators/computed.ts @@ -38,11 +38,11 @@ export class ComputedTranslator extends MethodTranslator implements InitializerC arkts.factory.createIdentifier(newName), factory.generateStateMgmtFactoryCall( StateManagementTypes.MAKE_COMPUTED, - this.method.scriptFunction.returnTypeAnnotation?.clone(), + this.method.function!.returnTypeAnnotation?.clone(), [ - arkts.factory.createArrowFunction( + arkts.factory.createArrowFunctionExpression( UIFactory.createScriptFunction({ - body: this.method.scriptFunction.body?.clone(), + body: this.method.function!.body?.clone(), modifiers: arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, }) @@ -58,7 +58,7 @@ export class ComputedTranslator extends MethodTranslator implements InitializerC const originGetter: arkts.MethodDefinition = UIFactory.updateMethodDefinition(this.method, { function: { - returnTypeAnnotation: this.method.scriptFunction.returnTypeAnnotation?.clone(), + returnTypeAnnotation: this.method.function!.returnTypeAnnotation?.clone(), body: arkts.factory.createBlock([ arkts.factory.createReturnStatement(this.generateComputedGet(newName)), ]), diff --git a/arkui-plugins/ui-plugins/property-translators/factory.ts b/arkui-plugins/ui-plugins/property-translators/factory.ts index 0cc0f24ef46b1d12804784a225739ba06b7005ad..caa6ad3b564be7a485461a82a3037c336f1f2ec0 100644 --- a/arkui-plugins/ui-plugins/property-translators/factory.ts +++ b/arkui-plugins/ui-plugins/property-translators/factory.ts @@ -169,7 +169,7 @@ export class factory { hasReceiver: boolean, bodyStatementsList: arkts.Statement[] ): arkts.ArrowFunctionExpression { - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( arkts.factory.createScriptFunction( arkts.BlockStatement.createBlockStatement(bodyStatementsList), arkts.factory.createFunctionSignature(typeParams, params ? params : [], returnType, hasReceiver), @@ -191,7 +191,7 @@ export class factory { undefined ), ], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), false, [ arkts.factory.createExpressionStatement( @@ -235,8 +235,8 @@ export class factory { args: arkts.Expression[] | undefined ): arkts.ETSNewClassInstanceExpression { return arkts.factory.createETSNewClassInstanceExpression( - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(className), arkts.factory.createTSTypeParameterInstantiation(typeAnnotation ? [typeAnnotation.clone()] : []) ) @@ -340,8 +340,8 @@ export class factory { property: arkts.ClassProperty ): arkts.ETSTypeReference { collectStateManagementTypeImport(stageManagementType); - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(stageManagementType), arkts.factory.createTSTypeParameterInstantiation([ property.typeAnnotation ? property.typeAnnotation.clone() : arkts.factory.createETSUndefinedType(), @@ -357,8 +357,8 @@ export class factory { const subscribedWatches: arkts.ClassProperty = arkts.factory.createClassProperty( arkts.factory.createIdentifier('subscribedWatches'), factory.generateStateMgmtFactoryCall(StateManagementTypes.MAKE_SUBSCRIBED_WATCHES, undefined, [], false), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(StateManagementTypes.SUBSCRIBED_WATCHES) ) ), @@ -432,14 +432,14 @@ export class factory { arkts.factory.createParameterDeclaration( arkts.factory.createIdentifier( paramName, - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(paramType)) + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier(paramType)) ) ), undefined ), ], - arkts.factory.createPrimitiveType(returnType), + arkts.factory.createETSPrimitiveType(returnType), false ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, @@ -476,8 +476,8 @@ export class factory { const v1RenderId: arkts.ClassProperty = arkts.factory.createClassProperty( arkts.factory.createIdentifier(ObservedNames.V1_RERENDER_ID), arkts.factory.createNumericLiteral(0), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(StateManagementTypes.RENDER_ID_TYPE) ) ), @@ -515,7 +515,7 @@ export class factory { undefined ), ], - returnTypeAnnotation: arkts.factory.createPrimitiveType( + returnTypeAnnotation: arkts.factory.createETSPrimitiveType( arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID ), flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, @@ -554,7 +554,7 @@ export class factory { undefined ), ], - returnTypeAnnotation: arkts.factory.createPrimitiveType( + returnTypeAnnotation: arkts.factory.createETSPrimitiveType( arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID ), flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, @@ -603,7 +603,7 @@ export class factory { static addMemoToBuilderClassMethod(method: arkts.MethodDefinition): arkts.MethodDefinition { if (hasDecorator(method, DecoratorNames.BUILDER)) { removeDecorator(method, DecoratorNames.BUILDER); - addMemoAnnotation(method.scriptFunction); + addMemoAnnotation(method.function!); } return method; } @@ -641,8 +641,8 @@ export class factory { static wrapInterfacePropertyType(type: arkts.TypeNode, wrapTypeName: StateManagementTypes): arkts.TypeNode { if (arkts.isETSUnionType(type)) { return arkts.factory.updateUnionType(type, [ - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(wrapTypeName), arkts.factory.createTSTypeParameterInstantiation([type.types[0]]) ) @@ -714,7 +714,7 @@ export class factory { ): arkts.MethodDefinition { if (method.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET) { const newType: arkts.TypeNode | undefined = factory.wrapStateManagementTypeToType( - method.scriptFunction.returnTypeAnnotation, + method.function!.returnTypeAnnotation, decorator ); const newOverLoads = method.overloads.map((overload) => { @@ -726,11 +726,11 @@ export class factory { method.setOverloads(newOverLoads); removeDecorator(method, decorator); if (!!newType) { - method.scriptFunction.setReturnTypeAnnotation(newType); + method.function!.setReturnTypeAnnotation(newType); } } else if (method.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET) { const newParam: arkts.Expression | undefined = factory.wrapStateManagementTypeToParam( - method.scriptFunction.params.at(0), + method.function!.params.at(0), decorator ); removeDecorator(method, decorator); @@ -832,7 +832,7 @@ export class factory { ), arkts.factory.createProperty( arkts.factory.createIdentifier(MonitorNames.VALUE_CALL_CACK), - arkts.factory.createArrowFunction( + arkts.factory.createArrowFunctionExpression( UIFactory.createScriptFunction({ flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, body: arkts.factory.createBlock([arkts.factory.createReturnStatement(monitorVariable)]), diff --git a/arkui-plugins/ui-plugins/property-translators/monitor.ts b/arkui-plugins/ui-plugins/property-translators/monitor.ts index 9dffc1ad8586177e7ec7805a3b8304387af5f11f..69064541966f1a641fe5800d8770b053477ea99a 100644 --- a/arkui-plugins/ui-plugins/property-translators/monitor.ts +++ b/arkui-plugins/ui-plugins/property-translators/monitor.ts @@ -86,7 +86,7 @@ export class MonitorTranslator extends MethodTranslator implements InitializerCo } generateLambdaArg(originalName: string): arkts.ArrowFunctionExpression { - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( UIFactory.createScriptFunction({ params: [UIFactory.createParameterDeclaration(MonitorNames.M_PARAM, MonitorNames.I_MONITOR)], body: arkts.factory.createBlock([ @@ -102,7 +102,7 @@ export class MonitorTranslator extends MethodTranslator implements InitializerCo } getValueInMonitorAnnotation(): string[] | undefined { - const annotations: readonly arkts.AnnotationUsage[] = this.method.scriptFunction.annotations; + const annotations: readonly arkts.AnnotationUsage[] = this.method.function!.annotations; for (let i = 0; i < annotations.length; i++) { const anno: arkts.AnnotationUsage = annotations[i]; if ( diff --git a/arkui-plugins/ui-plugins/property-translators/observedTrack.ts b/arkui-plugins/ui-plugins/property-translators/observedTrack.ts index 3694e1692ce12a4cb7d6085512fde11942df9b2e..ef6fbbbde29e851ddd244d228c8380e34365f2f8 100644 --- a/arkui-plugins/ui-plugins/property-translators/observedTrack.ts +++ b/arkui-plugins/ui-plugins/property-translators/observedTrack.ts @@ -163,7 +163,7 @@ export class ObservedTrackTranslator extends ObservedPropertyTranslator { originGetter, originGetter.kind, newGetter.name, - newGetter.scriptFunction.addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD), + newGetter.function!.addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD), originGetter.modifiers, false ); @@ -171,7 +171,7 @@ export class ObservedTrackTranslator extends ObservedPropertyTranslator { originSetter, originSetter.kind, newSetter.name, - newSetter.scriptFunction + newSetter.function! .addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_OVERLOAD) .addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD), originSetter.modifiers, @@ -189,7 +189,7 @@ export class ObservedTrackTranslator extends ObservedPropertyTranslator { return arkts.factory.createClassProperty( arkts.factory.createIdentifier(`${StateManagementTypes.META}_${originalName}`), factory.generateStateMgmtFactoryCall(StateManagementTypes.MAKE_MUTABLESTATE_META, undefined, [], false), - uiFactory.createTypeReferenceFromString(StateManagementTypes.MUTABLE_STATE_META), + uifactory.createTypeReferenceFromString(StateManagementTypes.MUTABLE_STATE_META), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, false ); diff --git a/arkui-plugins/ui-plugins/property-translators/observedV2Trace.ts b/arkui-plugins/ui-plugins/property-translators/observedV2Trace.ts index 547b9ab17932ff2cdc2d086f4715115aed48589d..28fd8081304441059813f76ca2a14dc3460e4551 100644 --- a/arkui-plugins/ui-plugins/property-translators/observedV2Trace.ts +++ b/arkui-plugins/ui-plugins/property-translators/observedV2Trace.ts @@ -176,7 +176,7 @@ export class ObservedV2TraceTranslator extends ObservedPropertyTranslator { originGetter, originGetter.kind, newGetter.name, - newGetter.scriptFunction.addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD), + newGetter.function!.addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD), originGetter.modifiers, false ); @@ -184,7 +184,7 @@ export class ObservedV2TraceTranslator extends ObservedPropertyTranslator { originSetter, originSetter.kind, newSetter.name, - newSetter.scriptFunction + newSetter.function! .addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_OVERLOAD) .addFlag(arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD), originSetter.modifiers, @@ -202,7 +202,7 @@ export class ObservedV2TraceTranslator extends ObservedPropertyTranslator { return arkts.factory.createClassProperty( arkts.factory.createIdentifier(`${StateManagementTypes.META}_${originalName}`), factory.generateStateMgmtFactoryCall(StateManagementTypes.MAKE_MUTABLESTATE_META, undefined, [], false), - uiFactory.createTypeReferenceFromString(StateManagementTypes.MUTABLE_STATE_META), + uifactory.createTypeReferenceFromString(StateManagementTypes.MUTABLE_STATE_META), this.isStatic ? arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC : arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, diff --git a/arkui-plugins/ui-plugins/property-translators/utils.ts b/arkui-plugins/ui-plugins/property-translators/utils.ts index 868e43aa1f8f43db12aadd71b33d5b7a119644a0..db66ab4fd292faf8d2b13f1e627f402a809b23e5 100644 --- a/arkui-plugins/ui-plugins/property-translators/utils.ts +++ b/arkui-plugins/ui-plugins/property-translators/utils.ts @@ -54,8 +54,8 @@ export function removeDecorator( ignoreDecl?: boolean ): void { if (arkts.isMethodDefinition(property)) { - property.scriptFunction.setAnnotations( - property.scriptFunction.annotations.filter( + property.function!.setAnnotations( + property.function!.annotations.filter( (anno) => !isDecoratorAnnotation(anno, decoratorName, ignoreDecl) ) ); @@ -75,7 +75,7 @@ export function hasDecoratorName( decoratorName: DecoratorNames ): boolean { if (arkts.isMethodDefinition(property)) { - return property.scriptFunction.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName, true)); + return property.function!.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName, true)); } return property.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName, true)); } @@ -90,7 +90,7 @@ export function hasDecorator( decoratorName: DecoratorNames ): boolean { if (arkts.isMethodDefinition(property)) { - return property.scriptFunction.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName)); + return property.function!.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName)); } return property.annotations.some((anno) => isDecoratorAnnotation(anno, decoratorName)); } @@ -118,7 +118,7 @@ export function findDecoratorByName( decoratorName: DecoratorNames ): arkts.AnnotationUsage | undefined { if (arkts.isMethodDefinition(property)) { - return property.scriptFunction.annotations.find((anno) => isDecoratorAnnotation(anno, decoratorName, true)); + return property.function!.annotations.find((anno) => isDecoratorAnnotation(anno, decoratorName, true)); } return property.annotations.find((anno) => isDecoratorAnnotation(anno, decoratorName, true)); } @@ -128,7 +128,7 @@ export function findDecorator( decoratorName: DecoratorNames ): arkts.AnnotationUsage | undefined { if (arkts.isMethodDefinition(property)) { - return property.scriptFunction.annotations.find((anno) => isDecoratorAnnotation(anno, decoratorName)); + return property.function!.annotations.find((anno) => isDecoratorAnnotation(anno, decoratorName)); } return property.annotations.find((anno) => isDecoratorAnnotation(anno, decoratorName)); } @@ -378,8 +378,8 @@ export function generateToRecord(newName: string, originalName: string): arkts.P false ), arkts.ETSNewClassInstanceExpression.createETSNewClassInstanceExpression( - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('Object')) + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier('Object')) ), [] ), diff --git a/arkui-plugins/ui-plugins/struct-translators/factory.ts b/arkui-plugins/ui-plugins/struct-translators/factory.ts index d4fd4e5d1d88d7b00caed14fdf65a0e4da916e03..794c5817bd0126ac5cfac38af764b5c0eddc58ff 100644 --- a/arkui-plugins/ui-plugins/struct-translators/factory.ts +++ b/arkui-plugins/ui-plugins/struct-translators/factory.ts @@ -109,27 +109,28 @@ export class factory { let modifiers: arkts.Es2pandaModifierFlags = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE; if (!scope.isDecl) { - body = arkts.factory.createBlock(PropertyCache.getInstance().getInitializeBody(scope.name)); + body = arkts.factory.createBlockStatement(PropertyCache.getInstance().getInitializeBody(scope.name) as arkts.Statement[]); modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC; } const scriptFunction: arkts.ScriptFunction = arkts.factory .createScriptFunction( body, - arkts.FunctionSignature.createFunctionSignature( - undefined, - [UIFactory.createInitializersOptionsParameter(optionsTypeName), UIFactory.createContentParameter()], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false - ), + // arkts.FunctionSignature.createFunctionSignature( + undefined, + [UIFactory.createInitializersOptionsParameter(optionsTypeName), UIFactory.createContentParameter()], + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, + // ), arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - modifiers - ) - .setIdent(updateKey); + modifiers, + updateKey, + undefined + ); return arkts.factory.createMethodDefinition( arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - updateKey, - scriptFunction, + updateKey.clone(), + arkts.factory.createFunctionExpression(updateKey.clone(), scriptFunction), modifiers, false ); @@ -167,13 +168,14 @@ export class factory { }); builderNode.setOverloads(newOverLoads); if (!!newType) { - builderNode.scriptFunction.setReturnTypeAnnotation(newType); + builderNode.function!.setReturnTypeAnnotation(newType); } } else if (builderNode.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET) { - const param = builderNode.scriptFunction.params[0] as arkts.ETSParameterExpression; - const newParam: arkts.Expression | undefined = arkts.factory.updateParameterDeclaration( + const param = builderNode.function!.params[0] as arkts.ETSParameterExpression; + const newParam: arkts.Expression | undefined = arkts.factory.updateETSParameterExpression( param, - arkts.factory.createIdentifier(param.identifier.name, newType), + arkts.factory.createIdentifier(param.ident!.name, newType), + false, param.initializer ); if (!!newParam) { @@ -195,28 +197,27 @@ export class factory { let modifiers: arkts.Es2pandaModifierFlags = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC | arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE; if (!scope.isDecl) { - body = arkts.factory.createBlock(PropertyCache.getInstance().getUpdateBody(scope.name)); + body = arkts.factory.createBlockStatement(PropertyCache.getInstance().getUpdateBody(scope.name) as arkts.Statement[]); modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC; } const scriptFunction: arkts.ScriptFunction = arkts.factory .createScriptFunction( body, - arkts.FunctionSignature.createFunctionSignature( - undefined, - [UIFactory.createInitializersOptionsParameter(optionsTypeName)], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false - ), + undefined, + [UIFactory.createInitializersOptionsParameter(optionsTypeName)], + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - modifiers - ) - .setIdent(updateKey); + modifiers, + updateKey.clone(), + undefined + ); return arkts.factory.createMethodDefinition( arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - updateKey, - scriptFunction, + updateKey.clone(), + arkts.factory.createFunctionExpression(updateKey.clone(), scriptFunction), modifiers, false ); @@ -234,24 +235,32 @@ export class factory { false ) ); - const body: arkts.BlockStatement = arkts.factory.createBlock([paramsCasted, returnRecord]); + const body: arkts.BlockStatement = arkts.factory.createBlockStatement([paramsCasted, returnRecord]); - const params = arkts.ETSParameterExpression.create( + const params = arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier('params', factory.generateTypeReferenceWithTypeName('Object')), + false, undefined ); + const methodId = arkts.factory.createIdentifier('__toRecord'); + const toRecordScriptFunction = arkts.factory.createScriptFunction( body, - arkts.FunctionSignature.createFunctionSignature(undefined, [params], factory.generateTypeRecord(), false), + undefined, + [params], + factory.generateTypeRecord(), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + methodId, + undefined ); return arkts.factory.createMethodDefinition( arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_CONSTRUCTOR, - arkts.factory.createIdentifier('__toRecord'), - toRecordScriptFunction, + methodId.clone(), + arkts.factory.createFunctionExpression(methodId.clone(), toRecordScriptFunction), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_OVERRIDE, false ); @@ -262,7 +271,6 @@ export class factory { */ static generateParamsCasted(optionsTypeName: string): arkts.VariableDeclaration { return arkts.factory.createVariableDeclaration( - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, [ arkts.factory.createVariableDeclarator( @@ -282,8 +290,8 @@ export class factory { * generate Record type. */ static generateTypeRecord(): arkts.ETSTypeReference { - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier('Record'), arkts.factory.createTSTypeParameterInstantiation([ factory.generateTypeReferenceWithTypeName('string'), @@ -297,8 +305,8 @@ export class factory { * create type reference with type name, e.g. number. */ static generateTypeReferenceWithTypeName(typeName: string): arkts.ETSTypeReference { - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(typeName)) + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier(typeName)) ); } @@ -355,17 +363,18 @@ export class factory { */ static createAniExtendValueParam(): arkts.ETSParameterExpression { const numberType = UIFactory.createTypeReferenceFromString('number'); - const AnimatableArithmeticType = arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + const AnimatableArithmeticType = arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(AnimationNames.ANIMATABLE_ARITHMETIC), arkts.factory.createTSTypeParameterInstantiation([UIFactory.createTypeReferenceFromString('T')]) ) ); - return arkts.factory.createParameterDeclaration( + return arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( 'value', - arkts.factory.createUnionType([numberType, AnimatableArithmeticType]) + arkts.factory.createETSUnionType([numberType, AnimatableArithmeticType]) ), + false, undefined ); } @@ -374,40 +383,50 @@ export class factory { * generate __createOrSetAnimatableProperty(...) for AnimatableExtend */ static createOrSetAniProperty(): arkts.MethodDefinition { - const funcNameParam: arkts.ETSParameterExpression = arkts.factory.createParameterDeclaration( + const funcNameParam: arkts.ETSParameterExpression = arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier('functionName', UIFactory.createTypeReferenceFromString('string')), + false, undefined ); - const cbParam = arkts.factory.createParameterDeclaration( + const cbParam = arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( 'callback', - arkts.factory.createFunctionType( - arkts.factory.createFunctionSignature( - undefined, - [factory.createAniExtendValueParam()], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false - ), + arkts.factory.createETSFunctionType( + undefined, + [factory.createAniExtendValueParam()], + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW ) ), + false, undefined ); return arkts.factory.createMethodDefinition( arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, arkts.factory.createIdentifier(AnimationNames.CREATE_OR_SET_ANIMATABLEPROPERTY), - UIFactory.createScriptFunction({ - typeParams: arkts.factory.createTypeParameterDeclaration( - [arkts.factory.createTypeParameter(arkts.factory.createIdentifier('T'))], - 0 - ), - params: [funcNameParam, factory.createAniExtendValueParam(), cbParam], - returnTypeAnnotation: arkts.factory.createPrimitiveType( - arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID - ), - flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - modifiers: arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, - }), + arkts.factory.createFunctionExpression( + arkts.factory.createIdentifier(AnimationNames.CREATE_OR_SET_ANIMATABLEPROPERTY), + UIFactory.createScriptFunction({ + typeParams: arkts.factory.createTSTypeParameterDeclaration( + [ + arkts.factory.createTypeParameter( + arkts.factory.createIdentifier('T'), + undefined, + undefined, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE + ) + ], + 0 + ), + params: [funcNameParam, factory.createAniExtendValueParam(), cbParam], + returnTypeAnnotation: arkts.factory.createETSPrimitiveType( + arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID + ), + flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, + modifiers: arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + }) + ), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, false ); @@ -418,29 +437,36 @@ export class factory { */ static createAnimationMethod(key: string): arkts.MethodDefinition { const aniparams: arkts.Expression[] = [ - arkts.factory.createParameterDeclaration( + arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( 'value', - arkts.factory.createUnionType([ - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('AnimateParam')) + arkts.factory.createETSUnionType([ + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier('AnimateParam')) ), arkts.factory.createETSUndefinedType(), ]) ), + false, undefined ), ]; + const keyIdent = arkts.factory.createIdentifier(key); const aniFunc = arkts.factory.createScriptFunction( undefined, - arkts.factory.createFunctionSignature(undefined, aniparams, arkts.TSThisType.createTSThisType(), false), + undefined, + aniparams, + arkts.TSThisType.createTSThisType(), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + keyIdent, + undefined ); return arkts.factory.createMethodDefinition( arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, - arkts.factory.createIdentifier(key), - aniFunc, + keyIdent.clone(), + arkts.factory.createFunctionExpression(keyIdent.clone(), aniFunc), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, false ); @@ -478,7 +504,7 @@ export class factory { return this.setStructConstructorToPrivate(member); } if (isKnownMethodDefinition(member, CustomComponentNames.COMPONENT_BUILD_ORI)) { - addMemoAnnotation(member.scriptFunction); + addMemoAnnotation(member.function!); } return member; } @@ -544,10 +570,10 @@ export class factory { projectConfig: ProjectConfig | undefined, resourceInfo: ResourceInfo ): arkts.CallExpression { - if (!arkts.isIdentifier(resourceNode.expression) || !projectConfig) { + if (!arkts.isIdentifier(resourceNode.callee) || !projectConfig) { return resourceNode; } - const resourceKind: Dollars = resourceNode.expression.name as Dollars; + const resourceKind: Dollars = resourceNode.callee.name as Dollars; if (arkts.isStringLiteral(resourceNode.arguments[0])) { return factory.processStringLiteralResourceNode( resourceNode, @@ -613,21 +639,22 @@ export class factory { } static createCustomDialogMethod(controller: string): arkts.MethodDefinition { - const param: arkts.ETSParameterExpression = arkts.factory.createParameterDeclaration( + const param: arkts.ETSParameterExpression = arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( CustomDialogNames.CONTROLLER, UIFactory.createTypeReferenceFromString(CustomDialogNames.CUSTOM_DIALOG_CONTROLLER) ), + false, undefined ); - const block = arkts.factory.createBlock( + const block = arkts.factory.createBlockStatement( controller.length !== 0 ? [ arkts.factory.createExpressionStatement( arkts.factory.createAssignmentExpression( generateThisBacking(backingField(controller)), - arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION, - arkts.factory.createIdentifier(CustomDialogNames.CONTROLLER) + arkts.factory.createIdentifier(CustomDialogNames.CONTROLLER), + arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION ) ), ] @@ -635,20 +662,23 @@ export class factory { ); const script = arkts.factory.createScriptFunction( block, - arkts.FunctionSignature.createFunctionSignature( - undefined, - [param], - arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false - ), + undefined, + [param], + arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + arkts.factory.createIdentifier(CustomDialogNames.SET_DIALOG_CONTROLLER_METHOD), + undefined ); return arkts.factory.createMethodDefinition( arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, arkts.factory.createIdentifier(CustomDialogNames.SET_DIALOG_CONTROLLER_METHOD), - script, + arkts.factory.createFunctionExpression( + arkts.factory.createIdentifier(CustomDialogNames.SET_DIALOG_CONTROLLER_METHOD), + script + ), arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, false ); @@ -708,9 +738,9 @@ export class factory { : Dollars.TRANSFORM_DOLLAR_RAWFILE; ImportCollector.getInstance().collectImport(transformedKey); const isDynamicBundleOrModule: boolean = isDynamicName(projectConfig); - const args: arkts.AstNode[] = [ - arkts.factory.createNumericLiteral(resourceParams.id), - arkts.factory.createNumericLiteral(resourceParams.type), + const args: arkts.Expression[] = [ + arkts.factory.createNumberLiteral(resourceParams.id), + arkts.factory.createNumberLiteral(resourceParams.type), arkts.factory.createStringLiteral(generateResourceBundleName(projectConfig, isDynamicBundleOrModule)), arkts.factory.createStringLiteral( generateResourceModuleName(projectConfig, isDynamicBundleOrModule, resourceModuleName, fromOtherModule) @@ -720,8 +750,8 @@ export class factory { return arkts.factory.updateCallExpression( resourceNode, arkts.factory.createIdentifier(transformedKey), + args, undefined, - args ); } @@ -805,8 +835,8 @@ export class factory { member = arkts.factory.updateMethodDefinition( member, member.kind, - member.name, - factory.transformAnimatableExtend(member.scriptFunction), + member.id!, + arkts.factory.createFunctionExpression(member.id?.clone(), factory.transformAnimatableExtend(member.function!)), member.modifiers, false ); @@ -923,7 +953,7 @@ export class factory { } static transformObservedV2Constuctor(definition: arkts.ClassDefinition, className: string): arkts.MethodDefinition { - const addConstructorNodes: arkts.AstNode[] = PropertyCache.getInstance().getConstructorBody(className); + const addConstructorNodes = PropertyCache.getInstance().getConstructorBody(className) as arkts.Statement[]; let originConstructorMethod: arkts.MethodDefinition | undefined = definition.body.find( (it) => arkts.isMethodDefinition(it) && @@ -934,7 +964,7 @@ export class factory { key: arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_CONSTRUCTOR_ORI), function: { key: arkts.factory.createIdentifier(CustomComponentNames.COMPONENT_CONSTRUCTOR_ORI), - body: arkts.factory.createBlock(addConstructorNodes), + body: arkts.factory.createBlockStatement(addConstructorNodes), flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_CONSTRUCTOR, modifiers: arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_CONSTRUCTOR, }, @@ -943,12 +973,12 @@ export class factory { }); } - const originBody = originConstructorMethod.scriptFunction.body as arkts.BlockStatement | undefined; + const originBody = originConstructorMethod.function?.body as arkts.BlockStatement | undefined; return UIFactory.updateMethodDefinition(originConstructorMethod, { function: { body: originBody - ? arkts.factory.updateBlock(originBody, [...originBody.statements, ...addConstructorNodes]) - : arkts.factory.createBlock(addConstructorNodes), + ? arkts.factory.updateBlockStatement(originBody, [...originBody.statements, ...addConstructorNodes]) + : arkts.factory.createBlockStatement(addConstructorNodes), }, }); } @@ -962,28 +992,29 @@ export class factory { ): arkts.ArrowFunctionExpression { const assignmentExpr = arkts.factory.createExpressionStatement( arkts.factory.createAssignmentExpression( - param.identifier.clone(), - arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION, - arkts.factory.createTSAsExpression(param.identifier.clone(), param.type as arkts.TypeNode, false) + param.ident?.clone(), + arkts.factory.createTSAsExpression(param.ident?.clone(), param.typeAnnotation, false), + arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION ) ); const numberType = UIFactory.createTypeReferenceFromString('number'); - const AnimatableArithmeticType = arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + const AnimatableArithmeticType = arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(AnimationNames.ANIMATABLE_ARITHMETIC), - arkts.factory.createTSTypeParameterInstantiation([param.type as arkts.TypeNode]) + arkts.factory.createTSTypeParameterInstantiation([param.typeAnnotation!]) ) ); ImportCollector.getInstance().collectImport(AnimationNames.ANIMATABLE_ARITHMETIC); - return arkts.factory.createArrowFunction( + return arkts.factory.createArrowFunctionExpression( UIFactory.createScriptFunction({ - body: arkts.factory.createBlock([assignmentExpr, ...originStatements]), + body: arkts.factory.createBlockStatement([assignmentExpr, ...originStatements]), params: [ - arkts.factory.createParameterDeclaration( + arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( - param.identifier.name, - arkts.factory.createUnionType([numberType, AnimatableArithmeticType]) + param.ident!.name, + arkts.factory.createETSUnionType([numberType, AnimatableArithmeticType]) ), + false, undefined ), ], @@ -996,7 +1027,7 @@ export class factory { * transform @AnimatableExtend method */ static transformAnimatableExtend(node: arkts.ScriptFunction): arkts.ScriptFunction { - if (!arkts.isEtsParameterExpression(node.params[1]) || !node.body || !arkts.isBlockStatement(node.body)) { + if (!arkts.isETSParameterExpression(node.params[1]) || !node.body || !arkts.isBlockStatement(node.body)) { return node; } const funcName: arkts.StringLiteral = arkts.factory.createStringLiteral(node.id?.name!); @@ -1011,25 +1042,27 @@ export class factory { false, false ), - undefined, [ funcName, - paramValue.identifier, + paramValue.ident!, factory.createAniExtendCbArg(paramValue, originStatements.slice(0, -1)), - ] + ], + undefined, + false, + false, ) ); return arkts.factory.updateScriptFunction( node, - arkts.factory.createBlock([createOrSetStatement, originStatements[originStatements.length - 1]]), - arkts.FunctionSignature.createFunctionSignature( - node.typeParams, - node.params, - node.returnTypeAnnotation, - node.hasReceiver - ), + arkts.factory.createBlockStatement([createOrSetStatement, originStatements[originStatements.length - 1]]), + node.typeParams, + node.params, + node.returnTypeAnnotation, + node.hasReceiver, node.flags, - node.modifiers + node.modifierFlags, + node.id, + node.annotations ); } @@ -1040,53 +1073,55 @@ export class factory { if (!arkts.isArrowFunctionExpression(node.arguments[1])) { return node; } - const argTypeParam: arkts.Expression = node.arguments[1].scriptFunction.params[0]; + const argTypeParam: arkts.Expression = node.arguments[1].function!.params[0]; if ( - !arkts.isEtsParameterExpression(argTypeParam) || - !argTypeParam.type || - !arkts.isTypeNode(argTypeParam.type) + !arkts.isETSParameterExpression(argTypeParam) || + !argTypeParam.typeAnnotation || + !arkts.isTypeNode(argTypeParam.typeAnnotation) ) { return node; } const referenceType = UIFactory.createComplexTypeFromStringAndTypeParameter('Array', [ - argTypeParam.type.clone(), + argTypeParam.typeAnnotation.clone(), ]); const newFunc = UIFactory.createScriptFunction({ - body: arkts.factory.createBlock([arkts.factory.createReturnStatement(node.arguments[0])]), + body: arkts.factory.createBlockStatement([arkts.factory.createReturnStatement(node.arguments[0])]), returnTypeAnnotation: referenceType, flags: arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW, modifiers: arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, }); const returnMemoableInfo = collectMemoableInfoInFunctionReturnType(newFunc); collectScriptFunctionReturnTypeFromInfo(newFunc, returnMemoableInfo); - const newArrowArg: arkts.ArrowFunctionExpression = arkts.factory.createArrowFunction(newFunc); - return arkts.factory.updateCallExpression(node, node.expression, node.typeArguments, [ + const newArrowArg: arkts.ArrowFunctionExpression = arkts.factory.createArrowFunctionExpression(newFunc); + return arkts.factory.updateCallExpression(node, node.callee, [ newArrowArg, ...node.arguments.slice(1), - ]); + ], node.typeParams); } static AddArrowTypeForParameter(node: arkts.MethodDefinition): arkts.MethodDefinition { - if (node.scriptFunction.params.length < 2) { + if (node.function!.params.length < 2) { return node; } - const paramFirst = node.scriptFunction.params[0]; - if (!arkts.isEtsParameterExpression(paramFirst) || !paramFirst.type || !arkts.isTypeNode(paramFirst.type)) { + const paramFirst = node.function!.params[0]; + if (!arkts.isETSParameterExpression(paramFirst) || !paramFirst.typeAnnotation || !arkts.isTypeNode(paramFirst.typeAnnotation)) { return node; } - const script = UIFactory.updateScriptFunction(node.scriptFunction, { + const script = UIFactory.updateScriptFunction(node.function!, { params: [ - arkts.factory.createParameterDeclaration( + arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier( - paramFirst.identifier.name, - UIFactory.createLambdaFunctionType([], paramFirst.type) + paramFirst.ident!.name, + UIFactory.createLambdaFunctionType([], paramFirst.typeAnnotation) ), + false, undefined ), - ...node.scriptFunction.params.slice(1), + ...node.function!.params.slice(1), ], }); - return arkts.factory.updateMethodDefinition(node, node.kind, node.name, script, node.modifiers, false); + const scriptExpr = arkts.factory.createFunctionExpression(node.id?.clone(), script) + return arkts.factory.updateMethodDefinition(node, node.kind, node.id, scriptExpr, node.modifiers, false); } static transformCallExpression( @@ -1109,10 +1144,10 @@ export class factory { static transformCustomDialogController( node: arkts.ETSNewClassInstanceExpression ): arkts.ETSNewClassInstanceExpression | arkts.Expression { - if (isInvalidDialogControllerOptions(node.getArguments)) { + if (isInvalidDialogControllerOptions(node.arguments)) { return node; } - const optionArg = node.getArguments[0]; + const optionArg = node.arguments[0]; const options: arkts.ObjectExpression = arkts.isObjectExpression(optionArg) ? optionArg : ((optionArg as arkts.TSAsExpression).expr as arkts.ObjectExpression); @@ -1124,22 +1159,22 @@ export class factory { const builder: arkts.Property = properties.at(builderIndex)!; const gensymName: string = GenSymGenerator.getInstance().id(); const newBuilderValue = this.createDialogBuilderArrow(builder.value!, gensymName); - const newProperty = arkts.factory.updateProperty(builder, builder.key, newBuilderValue); + const newProperty = arkts.factory.updateProperty( + builder, builder.kind, builder.key, newBuilderValue, builder.isMethod, builder.isComputed + ); const newObj = arkts.factory.updateObjectExpression( options, - arkts.Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_EXPRESSION, [ ...(options.properties as arkts.Property[]).slice(0, builderIndex), newProperty, ...(options.properties as arkts.Property[]).slice(builderIndex + 1), this.createBaseComponent(), - ], - false + ] ); const newOptions = arkts.isTSAsExpression(optionArg) ? arkts.factory.updateTSAsExpression(optionArg, newObj, optionArg.typeAnnotation, optionArg.isConst) : newObj; - const typeRef = node.getTypeRef as arkts.ETSTypeReference; + const typeRef = node.typeRef as arkts.ETSTypeReference; const newNode = arkts.factory.updateETSNewClassInstanceExpression(node, typeRef, [newOptions]); return factory.createBlockStatementForOptionalExpression(newNode, gensymName); } @@ -1147,14 +1182,14 @@ export class factory { static createDialogBuilderArrow(value: arkts.Expression, gensymName: string): arkts.Expression { if ( arkts.isCallExpression(value) && - arkts.isMemberExpression(value.expression) && - arkts.isIdentifier(value.expression.property) && - value.expression.property.name === BuilderLambdaNames.TRANSFORM_METHOD_NAME + arkts.isMemberExpression(value.callee) && + arkts.isIdentifier(value.callee.property) && + value.callee.property.name === BuilderLambdaNames.TRANSFORM_METHOD_NAME ) { return addMemoAnnotation( - arkts.factory.createArrowFunction( + arkts.factory.createArrowFunctionExpression( UIFactory.createScriptFunction({ - body: arkts.factory.createBlock([ + body: arkts.factory.createBlockStatement([ arkts.factory.createExpressionStatement( this.transformCustomDialogComponentCall(value, gensymName) ), @@ -1173,15 +1208,15 @@ export class factory { static transformCustomDialogComponentCall(value: arkts.CallExpression, gensymName: string): arkts.CallExpression { if (value.arguments.length >= 2 && arkts.isArrowFunctionExpression(value.arguments[1])) { - const originScript: arkts.ScriptFunction = value.arguments[1].scriptFunction; + const originScript: arkts.ScriptFunction = value.arguments[1].function!; const newScript: arkts.ScriptFunction = UIFactory.updateScriptFunction(originScript, { body: this.generateInstanceSetController(originScript.body, gensymName), }); - return arkts.factory.updateCallExpression(value, value.expression, value.typeArguments, [ + return arkts.factory.updateCallExpression(value, value.callee, [ value.arguments[0], - arkts.factory.updateArrowFunction(value.arguments[1], newScript), + arkts.factory.updateArrowFunctionExpression(value.arguments[1], newScript), ...value.arguments.slice(2), - ]); + ], value.typeParams); } return value; } @@ -1199,9 +1234,8 @@ export class factory { const instanceIdent: arkts.Identifier = arkts.factory.createIdentifier( BuilderLambdaNames.STYLE_ARROW_PARAM_NAME ); - return arkts.factory.updateBlock(body, [ + return arkts.factory.updateBlockStatement(body, [ arkts.factory.createVariableDeclaration( - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_CONST, arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_CONST, [ arkts.factory.createVariableDeclarator( @@ -1218,7 +1252,7 @@ export class factory { return body; } - static genertateControllerSetCall(instanceIdent: arkts.Identifier, gensymName: string): arkts.AstNode { + static genertateControllerSetCall(instanceIdent: arkts.Identifier, gensymName: string): arkts.Statement { return arkts.factory.createExpressionStatement( arkts.factory.createCallExpression( arkts.factory.createMemberExpression( @@ -1228,28 +1262,32 @@ export class factory { false, false ), - undefined, [ arkts.factory.createTSAsExpression( arkts.factory.createIdentifier(gensymName), UIFactory.createTypeReferenceFromString(CustomDialogNames.CUSTOM_DIALOG_CONTROLLER), false ), - ] + ], + undefined, + false, + false, ) ); } static createBaseComponent(): arkts.Property { return arkts.factory.createProperty( + arkts.Es2pandaPropertyKind.PROPERTY_KIND_INIT, arkts.factory.createIdentifier(CustomDialogNames.BASE_COMPONENT), - arkts.factory.createThisExpression() + arkts.factory.createThisExpression(), + false, + false, ); } static generateLetVariableDecl(left: arkts.Identifier): arkts.VariableDeclaration { return arkts.factory.createVariableDeclaration( - arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, arkts.Es2pandaVariableDeclarationKind.VARIABLE_DECLARATION_KIND_LET, [ arkts.factory.createVariableDeclarator( @@ -1272,8 +1310,8 @@ export class factory { arkts.factory.createExpressionStatement( arkts.factory.createAssignmentExpression( arkts.factory.createIdentifier(gensymName), - arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION, - newNode + newNode, + arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION ) ), arkts.factory.createExpressionStatement( diff --git a/arkui-plugins/ui-plugins/struct-translators/struct-transformer.ts b/arkui-plugins/ui-plugins/struct-translators/struct-transformer.ts index 3101184cdba3342b645ef30ed3c71c73166d4cfb..10d8d02c75c6113453fd9489e90de614bdd45907 100644 --- a/arkui-plugins/ui-plugins/struct-translators/struct-transformer.ts +++ b/arkui-plugins/ui-plugins/struct-translators/struct-transformer.ts @@ -64,7 +64,7 @@ export class StructTransformer extends AbstractVisitor { } } if (arkts.isMethodDefinition(node) && this.scope.customComponents.length > 0) { - const name = node.name.name; + const name = node.id!.name; const scopeInfo = this.scope.customComponents.pop()!; scopeInfo.hasInitializeStruct ||= name === CustomComponentNames.COMPONENT_INITIALIZE_STRUCT; scopeInfo.hasUpdateStruct ||= name === CustomComponentNames.COMPONENT_UPDATE_STRUCT; @@ -105,7 +105,7 @@ export class StructTransformer extends AbstractVisitor { } else if (arkts.isTSInterfaceDeclaration(node)) { return factory.tranformInterfaceMembers(node, this.externalSourceName); } - if (arkts.isEtsScript(node) && ImportCollector.getInstance().importInfos.length > 0) { + if (arkts.isETSModule(node) && ImportCollector.getInstance().importInfos.length > 0) { ImportCollector.getInstance().insertCurrentImports(this.program); } return node; diff --git a/arkui-plugins/ui-plugins/struct-translators/utils.ts b/arkui-plugins/ui-plugins/struct-translators/utils.ts index ecba338d0f2218eb219efc9b0dbd8431ded149ac..aa27e2a66058180a651e18472715f0d87882ae12 100644 --- a/arkui-plugins/ui-plugins/struct-translators/utils.ts +++ b/arkui-plugins/ui-plugins/struct-translators/utils.ts @@ -101,14 +101,14 @@ export function isEtsGlobalClass(node: arkts.ClassDeclaration): boolean { export function isResourceNode(node: arkts.CallExpression, ignoreDecl: boolean = false): boolean { if ( !( - arkts.isIdentifier(node.expression) && - (node.expression.name === Dollars.DOLLAR_RESOURCE || node.expression.name === Dollars.DOLLAR_RAWFILE) + arkts.isIdentifier(node.callee) && + (node.callee.name === Dollars.DOLLAR_RESOURCE || node.callee.name === Dollars.DOLLAR_RAWFILE) ) ) { return false; } if (!ignoreDecl) { - const decl = arkts.getDecl(node.expression); + const decl = arkts.getDecl(node.callee!); if (!decl) { return false; } @@ -123,8 +123,8 @@ export function isResourceNode(node: arkts.CallExpression, ignoreDecl: boolean = export function isForEachCall(node: arkts.CallExpression): boolean { if ( - arkts.isIdentifier(node.expression) && - node.expression.name === InnerComponentNames.FOR_EACH && + arkts.isIdentifier(node.callee) && + node.callee.name === InnerComponentNames.FOR_EACH && node.arguments.length >= 2 ) { return true; @@ -528,10 +528,10 @@ export function isDynamicName(projectConfig: ProjectConfig): boolean { * @param sourceName external source name. */ export function isForEachDecl(node: arkts.MethodDefinition, sourceName: string | undefined): boolean { - const isForEach: boolean = !!node.name && node.name.name === InnerComponentNames.FOR_EACH; + const isForEach: boolean = !!node.id && node.id.name === InnerComponentNames.FOR_EACH; const isMethodDecl: boolean = - !!node.scriptFunction && - arkts.hasModifierFlag(node.scriptFunction, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE); + !!node.function && + arkts.hasModifierFlag(node.function, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE); return isForEach && isMethodDecl && !!sourceName && sourceName === ARKUI_FOREACH_SOURCE_NAME; } diff --git a/arkui-plugins/ui-plugins/ui-factory.ts b/arkui-plugins/ui-plugins/ui-factory.ts index c8c7cfc6f1689a4adbd58177a3305f8f8ba06907..d7ceadf89d974f64921b1d8212597e95ccd250d6 100644 --- a/arkui-plugins/ui-plugins/ui-factory.ts +++ b/arkui-plugins/ui-plugins/ui-factory.ts @@ -68,20 +68,18 @@ export class factory { * create `instance: ` as parameter */ static createInstanceParameter(typeName: string): arkts.ETSParameterExpression { - return arkts.factory.createParameterDeclaration(factory.createInstanceIdentifier(typeName), undefined); + return arkts.factory.createETSParameterExpression(factory.createInstanceIdentifier(typeName), false, undefined); } /** * create `(instance: ) => void` */ static createStyleLambdaFunctionType(typeName: string): arkts.ETSFunctionType { - return arkts.factory.createFunctionType( - arkts.FunctionSignature.createFunctionSignature( - undefined, - [factory.createInstanceParameter(typeName)], - factory.createTypeReferenceFromString(typeName), - false - ), + return arkts.factory.createETSFunctionType( + undefined, + [factory.createInstanceParameter(typeName)], + factory.createTypeReferenceFromString(typeName), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW ); } @@ -92,7 +90,7 @@ export class factory { static createStyleIdentifier(typeName: string): arkts.Identifier { return arkts.factory.createIdentifier( BuilderLambdaNames.STYLE_PARAM_NAME, - arkts.factory.createUnionType([ + arkts.factory.createETSUnionType([ factory.createStyleLambdaFunctionType(typeName), arkts.factory.createETSUndefinedType(), ]) @@ -105,7 +103,7 @@ export class factory { static createInitializerOptionsIdentifier(optionsName: string): arkts.Identifier { return arkts.factory.createIdentifier( CustomComponentNames.COMPONENT_INITIALIZERS_NAME, - arkts.factory.createUnionType([ + arkts.factory.createETSUnionType([ factory.createTypeReferenceFromString(optionsName), arkts.factory.createETSUndefinedType(), ]) @@ -116,8 +114,9 @@ export class factory { * create `initializers: | undefined` as parameter */ static createInitializersOptionsParameter(optionsName: string): arkts.ETSParameterExpression { - return arkts.factory.createParameterDeclaration( + return arkts.factory.createETSParameterExpression( factory.createInitializerOptionsIdentifier(optionsName), + false, undefined ); } @@ -128,7 +127,7 @@ export class factory { static createContentIdentifier(): arkts.Identifier { return arkts.factory.createIdentifier( BuilderLambdaNames.CONTENT_PARAM_NAME, - arkts.factory.createUnionType([factory.createLambdaFunctionType(), arkts.factory.createETSUndefinedType()]) + arkts.factory.createETSUnionType([factory.createLambdaFunctionType(), arkts.factory.createETSUndefinedType()]) ); } @@ -137,7 +136,7 @@ export class factory { */ static createContentParameter(): arkts.ETSParameterExpression { const contentParam: arkts.Identifier = factory.createContentIdentifier(); - const param: arkts.ETSParameterExpression = arkts.factory.createParameterDeclaration(contentParam, undefined); + const param: arkts.ETSParameterExpression = arkts.factory.createETSParameterExpression(contentParam, false, undefined); addMemoAnnotation(param); return param; } @@ -146,8 +145,8 @@ export class factory { * create type from string */ static createTypeReferenceFromString(name: string): arkts.TypeNode { - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(name)) + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier(name)) ); } @@ -155,8 +154,8 @@ export class factory { * create complex type from string and type parameter, e.g. `Set` */ static createComplexTypeFromStringAndTypeParameter(name: string, params: arkts.TypeNode[]): arkts.TypeNode { - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( + return arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart( arkts.factory.createIdentifier(name), arkts.factory.createTSTypeParameterInstantiation(params) ) @@ -170,13 +169,11 @@ export class factory { params?: arkts.Expression[], returnType?: arkts.TypeNode | undefined ): arkts.ETSFunctionType { - return arkts.factory.createFunctionType( - arkts.FunctionSignature.createFunctionSignature( - undefined, - params ?? [], - returnType ?? arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), - false - ), + return arkts.factory.createETSFunctionType( + undefined, + params ?? [], + returnType ?? arkts.factory.createETSPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_VOID), + false, arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_ARROW ); } @@ -201,21 +198,15 @@ export class factory { const newFunc: arkts.ScriptFunction = arkts.factory.updateScriptFunction( original, config.body ?? original.body, - arkts.factory.createFunctionSignature( - config.typeParams ?? original.typeParams, - config.params ?? original.params, - config.returnTypeAnnotation ?? original.returnTypeAnnotation, - config.hasReceiver ?? original.hasReceiver - ), + config.typeParams ?? original.typeParams, + config.params ?? original.params, + config.returnTypeAnnotation ?? original.returnTypeAnnotation, + config.hasReceiver ?? original.hasReceiver, config.flags ?? original.flags, - config.modifiers ?? original.modifiers + config.modifiers ?? original.modifiers, + config.key ?? original.id, + config.annotations ?? original.annotations ); - if (!!config.key) { - newFunc.setIdent(config.key); - } - if (!!config.annotations) { - newFunc.setAnnotations(config.annotations); - } return newFunc; } @@ -225,21 +216,15 @@ export class factory { static createScriptFunction(config: Partial): arkts.ScriptFunction { const newFunc: arkts.ScriptFunction = arkts.factory.createScriptFunction( config.body ?? undefined, - arkts.factory.createFunctionSignature( - config.typeParams ?? undefined, - config.params ?? [], - config.returnTypeAnnotation ?? undefined, - config.hasReceiver ?? false - ), + config.typeParams ?? undefined, + config.params ?? [], + config.returnTypeAnnotation ?? undefined, + config.hasReceiver ?? false, config.flags ?? arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_NONE, - config.modifiers ?? arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE + config.modifiers ?? arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, + config.key, + config.annotations, ); - if (!!config.key) { - newFunc.setIdent(config.key); - } - if (!!config.annotations) { - newFunc.setAnnotations(config.annotations); - } return newFunc; } @@ -250,8 +235,8 @@ export class factory { original: arkts.MethodDefinition, config: PartialNested ): arkts.MethodDefinition { - const key: arkts.Identifier = config.key ?? original.name; - const newFunc: arkts.ScriptFunction = factory.updateScriptFunction(original.scriptFunction, { + const key: arkts.Identifier = config.key ?? original.id!; + const newFunc: arkts.ScriptFunction = factory.updateScriptFunction(original.function!, { ...config.function, key, }); @@ -259,7 +244,7 @@ export class factory { original, config.kind ?? original.kind, key, - newFunc, + arkts.factory.createFunctionExpression(key.clone(), newFunc), config.modifiers ?? original.modifiers, config.isComputed ?? false ); @@ -280,7 +265,7 @@ export class factory { const newMethod: arkts.MethodDefinition = arkts.factory.createMethodDefinition( config.kind ?? arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_NONE, config.key!, - newFunc, + arkts.factory.createFunctionExpression(config.key!.clone(), newFunc), config.modifiers ?? arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, config.isComputed ?? false ); @@ -297,7 +282,7 @@ export class factory { config: PartialExcept ): arkts.AnnotationDeclaration { const intrinsicAnnotations: arkts.AnnotationUsage[] = [ - arkts.factory.create1AnnotationUsage(arkts.factory.createIdentifier('Retention'), [ + arkts.factory.createAnnotationUsage(arkts.factory.createIdentifier('Retention'), [ arkts.factory.createClassProperty( arkts.factory.createIdentifier('policy'), arkts.factory.createStringLiteral('SOURCE'), @@ -330,7 +315,7 @@ export class factory { property.key && arkts.isIdentifier(property.key) ) { - return arkts.factory.update1AnnotationUsage(anno, anno.expr, [ + return arkts.factory.updateAnnotationUsage(anno, anno.expr, [ ...anno.properties, factory.createAliasClassProperty(property.key), ]); @@ -347,7 +332,7 @@ export class factory { static createAliasClassProperty(value: arkts.Identifier): arkts.ClassProperty { return arkts.factory.createClassProperty( arkts.factory.createIdentifier('alias'), - arkts.factory.create1StringLiteral(value.name), + arkts.factory.createStringLiteral(value.name), undefined, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, false @@ -376,8 +361,8 @@ export class factory { typeParameters?: arkts.TSTypeParameterInstantiation ): arkts.TSClassImplements { return arkts.factory.createTSClassImplements( - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(interfaceName)) + arkts.factory.createETSTypeReference( + arkts.factory.createETSTypeReferencePart(arkts.factory.createIdentifier(interfaceName)) ), typeParameters ); @@ -447,7 +432,7 @@ export class factory { * * @param method method definition node */ - static generateMemberExpression(object: arkts.AstNode, property: string, optional = false): arkts.MemberExpression { + static generateMemberExpression(object: arkts.Expression, property: string, optional = false): arkts.MemberExpression { return arkts.factory.createMemberExpression( object, arkts.factory.createIdentifier(property), @@ -463,10 +448,11 @@ export class factory { static createParameterDeclaration( keyName: string, typeName: string, - initializers?: arkts.AstNode + initializers?: arkts.Expression ): arkts.ETSParameterExpression { - return arkts.factory.createParameterDeclaration( + return arkts.factory.createETSParameterExpression( arkts.factory.createIdentifier(keyName, this.createTypeReferenceFromString(typeName)), + false, initializers ); } diff --git a/arkui-plugins/ui-plugins/utils.ts b/arkui-plugins/ui-plugins/utils.ts index 5bcfa691802aa287fc5fb41092f0ed976b0323d3..5b30aec62b90545025f9cd663aa8078b670ba236 100644 --- a/arkui-plugins/ui-plugins/utils.ts +++ b/arkui-plugins/ui-plugins/utils.ts @@ -207,13 +207,13 @@ export function isCustomComponentAnnotation( } export function collectCustomComponentScopeInfo( - node: arkts.ClassDeclaration | arkts.StructDeclaration + node: arkts.ClassDeclaration | arkts.ETSStructDeclaration ): CustomComponentInfo | undefined { const definition: arkts.ClassDefinition | undefined = node.definition; if (!definition || !definition?.ident?.name) { return undefined; } - const isStruct = arkts.isStructDeclaration(node); + const isStruct = arkts.isETSStructDeclaration(node); const isDecl: boolean = arkts.hasModifierFlag(node, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_DECLARE); const isCustomComponentClassDecl = !isStruct && isDecl; const shouldIgnoreDecl = isStruct || isDecl; @@ -268,8 +268,8 @@ export function getAnnotationInfoForStruct( return { isComponent, isComponentV2, isEntry, isReusable, isReusableV2, isCustomLayout, isCustomDialog }; } -export function isComponentStruct(node: arkts.StructDeclaration, scopeInfo: CustomComponentInfo): boolean { - return scopeInfo.name === node.definition.ident?.name; +export function isComponentStruct(node: arkts.ETSStructDeclaration, scopeInfo: CustomComponentInfo): boolean { + return scopeInfo.name === node.definition!.ident?.name; } /** @@ -319,19 +319,19 @@ export function isKnownMethodDefinition(method: arkts.MethodDefinition, name: st } // For now, we only considered matched method name. - const isNameMatched: boolean = method.name?.name === name; + const isNameMatched: boolean = method.id?.name === name; return isNameMatched; } export function isSpecificNewClass(node: arkts.ETSNewClassInstanceExpression, className: string): boolean { if ( - node.getTypeRef && - arkts.isETSTypeReference(node.getTypeRef) && - node.getTypeRef.part && - arkts.isETSTypeReferencePart(node.getTypeRef.part) && - node.getTypeRef.part.name && - arkts.isIdentifier(node.getTypeRef.part.name) && - node.getTypeRef.part.name.name === className + node.typeRef && + arkts.isETSTypeReference(node.typeRef) && + node.typeRef.part && + arkts.isETSTypeReferencePart(node.typeRef.part) && + node.typeRef.part.name && + arkts.isIdentifier(node.typeRef.part.name) && + node.typeRef.part.name.name === className ) { return true; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/build-root-node.ts b/arkui-plugins/ui-syntax-plugins/rules/build-root-node.ts index a914891f9a65984a9b399a34ac34dbb40f4000cf..bc74c28694cc5187338fa91ba0f71161d900121d 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/build-root-node.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/build-root-node.ts @@ -29,7 +29,7 @@ class BuildRootNodeRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } const entryDecoratorUsage = getAnnotationUsage(node, PresetDecorators.ENTRY); @@ -37,8 +37,8 @@ class BuildRootNodeRule extends AbstractUISyntaxRule { if (!arkts.isMethodDefinition(member) || getIdentifierName(member.name) !== BUILD_NAME) { return; } - const blockStatement = member.scriptFunction.body; - const buildNode = member.scriptFunction.id; + const blockStatement = member.function!.body; + const buildNode = member.function!.id; if (!blockStatement || !arkts.isBlockStatement(blockStatement) || !buildNode) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/builderparam-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/builderparam-decorator-check.ts index ac532a3e906f50277ca0328d564a391b1fbc946a..2c9cb9965158b4a57a0d99305c6328eff3ca02b4 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/builderparam-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/builderparam-decorator-check.ts @@ -42,7 +42,7 @@ class BuilderParamDecoratorCheckRule extends AbstractUISyntaxRule { return; } node.getChildren().forEach((member) => { - if (!arkts.isStructDeclaration(member) || !member.definition.ident) { + if (!arkts.isETSStructDeclaration(member) || !member.definition.ident) { return; } let count: number = 0; @@ -113,7 +113,7 @@ class BuilderParamDecoratorCheckRule extends AbstractUISyntaxRule { } let structName: string = getIdentifierName(node); let structNode = node.parent; - while (!arkts.isStructDeclaration(structNode)) { + while (!arkts.isETSStructDeclaration(structNode)) { if (!structNode.parent) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/check-construct-private-parameter.ts b/arkui-plugins/ui-syntax-plugins/rules/check-construct-private-parameter.ts index 21cab0ab1a3c1015fd439f407dc13579f51e2121..64fe5a49ccbd9b5961e4e7984117c7ab1c7eb714 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/check-construct-private-parameter.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/check-construct-private-parameter.ts @@ -30,11 +30,11 @@ class CheckConstructPrivateParameterRule extends AbstractUISyntaxRule { this.privatePropertyMap = new Map(); } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { // Check if the current node is the root node if (arkts.nodeType(node) === arkts.Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE) { node.getChildren().forEach((member) => { - if (!arkts.isStructDeclaration(member) || !member.definition.ident || !member.definition.ident.name) { + if (!arkts.isETSStructDeclaration(member) || !member.definition.ident || !member.definition.ident.name) { return; } const structName: string = member.definition.ident.name; diff --git a/arkui-plugins/ui-syntax-plugins/rules/check-decorated-property-type.ts b/arkui-plugins/ui-syntax-plugins/rules/check-decorated-property-type.ts index 90c6a82eda041ef9e6a4a36cd1651ab4c8f68e70..4f173c39843efbba078cc58771a26fd8fe2e37e7 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/check-decorated-property-type.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/check-decorated-property-type.ts @@ -41,8 +41,8 @@ class CheckDecoratedPropertyTypeRule extends AbstractUISyntaxRule { }; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isStructDeclaration(node)) { + public parsed(node: arkts.ETSStructDeclaration): void { + if (!arkts.isETSStructDeclaration(node)) { return; } if (!node.definition) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/check-property-modifiers.ts b/arkui-plugins/ui-syntax-plugins/rules/check-property-modifiers.ts index 8081137833a846d3299563d85c484241fceca8ce..50c7c927440b9ad1fc223530857608bc60a58cf2 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/check-property-modifiers.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/check-property-modifiers.ts @@ -45,8 +45,8 @@ class CheckPropertyModifiersRule extends AbstractUISyntaxRule { }; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isStructDeclaration(node)) { + public parsed(node: arkts.ETSStructDeclaration): void { + if (!arkts.isETSStructDeclaration(node)) { return; } node.definition.body.forEach(member => { diff --git a/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-init-check.ts b/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-init-check.ts index 42c497eb713c8cc2b1a0cb47ef43e23a3423cbc9..eecb2ecc81db51ca1d1c330408967471b0641493 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-init-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-init-check.ts @@ -30,7 +30,7 @@ class ComponentComponentV2InitCheckRule extends AbstractUISyntaxRule { this.componentV1WithLinkList = []; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.initComponentV1WithLinkList(node); this.checkComponentInitLink(node); } @@ -40,7 +40,7 @@ class ComponentComponentV2InitCheckRule extends AbstractUISyntaxRule { return; } node.getChildren().forEach((member) => { - if (!arkts.isStructDeclaration(member) || !member.definition.ident || + if (!arkts.isETSStructDeclaration(member) || !member.definition.ident || !hasAnnotation(member?.definition.annotations, PresetDecorators.COMPONENT_V1)) { return; } @@ -65,7 +65,7 @@ class ComponentComponentV2InitCheckRule extends AbstractUISyntaxRule { return; } let structNode = node.parent; - while (!arkts.isStructDeclaration(structNode)) { + while (!arkts.isETSStructDeclaration(structNode)) { if (!structNode.parent) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-mix-use-check.ts b/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-mix-use-check.ts index 70714c3b382345f43e170d7754cb75833dae0bbf..42284724f1e831f658ed8cbe7043b89cbae6f840 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-mix-use-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/component-componentV2-mix-use-check.ts @@ -47,7 +47,7 @@ class ComponentComponentV2MixUseCheckRule extends AbstractUISyntaxRule { this.findAllTSTypeAliasDeclaration(node); } - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { this.processComponentAnnotations(node); } } @@ -109,7 +109,7 @@ class ComponentComponentV2MixUseCheckRule extends AbstractUISyntaxRule { } private processComponentAnnotations( - node: arkts.StructDeclaration + node: arkts.ETSStructDeclaration ): void { node.definition.annotations.forEach((anno) => { if (!anno.expr) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/componentV2-mix-check.ts b/arkui-plugins/ui-syntax-plugins/rules/componentV2-mix-check.ts index 7db39458228955d4c9ae1a445ab357ba01ce48a7..bdb133a97ccb179e192521158e3765533cfdda59 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/componentV2-mix-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/componentV2-mix-check.ts @@ -25,7 +25,7 @@ class ComponentV2MixCheckRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } const definition = node.definition; diff --git a/arkui-plugins/ui-syntax-plugins/rules/componentV2-state-usage-validation.ts b/arkui-plugins/ui-syntax-plugins/rules/componentV2-state-usage-validation.ts index 2f62ea5af878d57853d78e6e6147cbcdc2ef0bed..0dee9a017aea0cc57e6c800d4dc7d84c1fcb3e0d 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/componentV2-state-usage-validation.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/componentV2-state-usage-validation.ts @@ -51,13 +51,13 @@ class ComponentV2StateUsageValidationRule extends AbstractUISyntaxRule { // Rule 5: Local, Param, Event decorators must be used with Property this.checkuseStateDecoratorsWithProperty(node); } - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.validateClassPropertyDecorators(node); } - private hasComponentV2Annotation = (node: arkts.StructDeclaration): boolean => !!getAnnotationUsage(node, + private hasComponentV2Annotation = (node: arkts.ETSStructDeclaration): boolean => !!getAnnotationUsage(node, PresetDecorators.COMPONENT_V2); private checkMultipleBuiltInDecorators(member: arkts.ClassProperty, @@ -159,7 +159,7 @@ class ComponentV2StateUsageValidationRule extends AbstractUISyntaxRule { }); } - private validateClassPropertyDecorators(node: arkts.StructDeclaration): void { + private validateClassPropertyDecorators(node: arkts.ETSStructDeclaration): void { this.checkuseStateDecoratorsWithProperty(node.definition); const isComponentV2 = this.hasComponentV2Annotation(node); node.definition.body.forEach(member => { @@ -217,7 +217,7 @@ class ComponentV2StateUsageValidationRule extends AbstractUISyntaxRule { return; } node.getChildren().forEach((member) => { - if (!arkts.isStructDeclaration(member) || !member.definition.ident || + if (!arkts.isETSStructDeclaration(member) || !member.definition.ident || !this.checkDecorator(member.definition.annotations, PresetDecorators.COMPONENT_V2)) { return; } @@ -267,7 +267,7 @@ class ComponentV2StateUsageValidationRule extends AbstractUISyntaxRule { return; } let structNode = node.parent; - while (!arkts.isStructDeclaration(structNode)) { + while (!arkts.isETSStructDeclaration(structNode)) { if (!structNode.parent) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/computed-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/computed-decorator-check.ts index 2a1d477abd09ebef56d583a9306560881e4d3070..7fe04063d9332f5e184ec7633acf9674a749d93b 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/computed-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/computed-decorator-check.ts @@ -37,7 +37,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { this.validateComponentV2InStruct(node); this.validateStructBody(node); } @@ -47,7 +47,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { } } - private validateStructBody(node: arkts.StructDeclaration): void { + private validateStructBody(node: arkts.ETSStructDeclaration): void { let computedDecorator: arkts.AnnotationUsage | undefined; node.definition.body.forEach((member) => { if (arkts.isClassProperty(member)) { @@ -57,7 +57,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { if (arkts.isMethodDefinition(member)) { const methodName = getIdentifierName(member.name); - computedDecorator = findDecorator(member.scriptFunction, PresetDecorators.COMPUTED); + computedDecorator = findDecorator(member.function!, PresetDecorators.COMPUTED); this.validateComputedMethodKind(member, computedDecorator, methodName); if (member.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET) { @@ -125,7 +125,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { } private validateBuildMethod(member: arkts.MethodDefinition): void { - member.scriptFunction.body?.getChildren().forEach((childNode) => { + member.function!.body?.getChildren().forEach((childNode) => { if (!arkts.isExpressionStatement(childNode)) { return; } @@ -210,7 +210,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { if (arkts.isMethodDefinition(member)) { this.validateComputedInClass(node, member, observedV2Decorator, observedDecorator); - const computedDecorator = findDecorator(member.scriptFunction, PresetDecorators.COMPUTED); + const computedDecorator = findDecorator(member.function!, PresetDecorators.COMPUTED); if (!arkts.isIdentifier(member.name)) { return; } @@ -221,7 +221,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { }); } - private validateComponentV2InStruct(node: arkts.StructDeclaration): void { + private validateComponentV2InStruct(node: arkts.ETSStructDeclaration): void { const componentV2Decorator = getAnnotationUsage(node, PresetDecorators.COMPONENT_V2); const componentDecorator = getAnnotationUsage(node, PresetDecorators.COMPONENT_V1); @@ -233,12 +233,12 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { } private checkComponentV2InStruct( - node: arkts.StructDeclaration | arkts.ClassDeclaration, + node: arkts.ETSStructDeclaration | arkts.ClassDeclaration, member: arkts.MethodDefinition, componentV2Decorator: arkts.AnnotationUsage | undefined, componentDecorator: arkts.AnnotationUsage | undefined ): void { - const computedDecorator = findDecorator(member.scriptFunction, PresetDecorators.COMPUTED); + const computedDecorator = findDecorator(member.function!, PresetDecorators.COMPUTED); if (computedDecorator && !componentV2Decorator && !componentDecorator) { this.report({ node: computedDecorator, @@ -276,7 +276,7 @@ class ComputedDecoratorCheckRule extends AbstractUISyntaxRule { observedV2Decorator: arkts.AnnotationUsage | undefined, observedDecorator: arkts.AnnotationUsage | undefined ): void { - const computedDecorator = findDecorator(member.scriptFunction, PresetDecorators.COMPUTED); + const computedDecorator = findDecorator(member.function!, PresetDecorators.COMPUTED); if (computedDecorator && !observedV2Decorator && !observedDecorator && arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET === member.kind) { this.report({ diff --git a/arkui-plugins/ui-syntax-plugins/rules/construct-parameter-literal.ts b/arkui-plugins/ui-syntax-plugins/rules/construct-parameter-literal.ts index 784cecad5d7f20b648e56ea33384bff7d6718ee6..7982cee6174ed60622ec4521636258388970bda0 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/construct-parameter-literal.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/construct-parameter-literal.ts @@ -32,7 +32,7 @@ class ConstructParameterLiteralRule extends AbstractUISyntaxRule { this.linkMap = new Map(); } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.initMap(node); this.checkInitializeWithLiteral(node); } @@ -76,7 +76,7 @@ class ConstructParameterLiteralRule extends AbstractUISyntaxRule { return; } node.getChildren().forEach((member) => { - if (!(arkts.isStructDeclaration(member))) { + if (!(arkts.isETSStructDeclaration(member))) { return; } if (!member.definition || !member.definition.ident || !arkts.isIdentifier(member.definition.ident)) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/construct-parameter.ts b/arkui-plugins/ui-syntax-plugins/rules/construct-parameter.ts index 9a4d5695c7fa398390b6991e3c00273a671646b3..3259f3bf22711edf2cc6631863aa1de40986e560 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/construct-parameter.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/construct-parameter.ts @@ -64,14 +64,14 @@ class ConstructParameterRule extends AbstractUISyntaxRule { this.builderFunctionList = []; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.initList(node); this.initPropertyMap(node); this.checkConstructParameter(node); } private getPropertyAnnotationName(node: arkts.AstNode, propertyName: string): string { - while (!arkts.isStructDeclaration(node)) { + while (!arkts.isETSStructDeclaration(node)) { if (!node.parent) { return ''; } @@ -83,7 +83,7 @@ class ConstructParameterRule extends AbstractUISyntaxRule { annotationNames = getClassPropertyAnnotationNames(item); } if (arkts.isMethodDefinition(item) && getIdentifierName(item.name) === propertyName) { - annotationNames = item.scriptFunction.annotations.map((annotation) => + annotationNames = item.function!.annotations.map((annotation) => getAnnotationName(annotation) ); } @@ -120,8 +120,8 @@ class ConstructParameterRule extends AbstractUISyntaxRule { } member.annotations.forEach(annotation => { if (annotation.expr && getIdentifierName(annotation.expr) === PresetDecorators.BUILDER && - member.scriptFunction.id) { - this.builderFunctionList.push(member.scriptFunction.id.name); + member.function!.id) { + this.builderFunctionList.push(member.function!.id.name); } }); } @@ -181,7 +181,7 @@ class ConstructParameterRule extends AbstractUISyntaxRule { return; } node.getChildren().forEach((member) => { - if (!arkts.isStructDeclaration(member) || !member.definition.ident) { + if (!arkts.isETSStructDeclaration(member) || !member.definition.ident) { return; } let structName: string = member.definition.ident?.name ?? ''; diff --git a/arkui-plugins/ui-syntax-plugins/rules/consumer-provider-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/consumer-provider-decorator-check.ts index 9f56e39151138ad28720bd8da0b142954c699aa9..d4c5165d6ef07dff3de5ccd50035f1fc07abd501 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/consumer-provider-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/consumer-provider-decorator-check.ts @@ -63,7 +63,7 @@ class ConsumerProviderDecoratorCheckRule extends AbstractUISyntaxRule { } private rememberStructName(node: arkts.AstNode): void { - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { node.definition.annotations.forEach((anno) => { if (!anno.expr) { return; @@ -78,7 +78,7 @@ class ConsumerProviderDecoratorCheckRule extends AbstractUISyntaxRule { } } - private processStructMembers(node: arkts.StructDeclaration, structName: string): void { + private processStructMembers(node: arkts.ETSStructDeclaration, structName: string): void { node.definition.body.forEach((member) => { // When a member variable is @consumer modified, it is stored to mark fields that cannot be initialized if (arkts.isClassProperty(member)) { @@ -112,7 +112,7 @@ class ConsumerProviderDecoratorCheckRule extends AbstractUISyntaxRule { this.validateDecorator(node, this.messages.providerAndConsumerOnlyOnProperty, PresetDecorators.PROVIDER); } - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { node.definition.body.forEach(member => { if (arkts.isClassProperty(member)) { this.validateMemberDecorators(member); @@ -181,9 +181,9 @@ class ConsumerProviderDecoratorCheckRule extends AbstractUISyntaxRule { } if (arkts.isMethodDefinition(member)) { this.validateDecorator( - member.scriptFunction, this.messages.providerAndConsumerOnlyInStruct, PresetDecorators.CONSUMER); + member.function!, this.messages.providerAndConsumerOnlyInStruct, PresetDecorators.CONSUMER); this.validateDecorator( - member.scriptFunction, this.messages.providerAndConsumerOnlyInStruct, PresetDecorators.PROVIDER); + member.function!, this.messages.providerAndConsumerOnlyInStruct, PresetDecorators.PROVIDER); } }); return; diff --git a/arkui-plugins/ui-syntax-plugins/rules/custom-dialog-missing-controller.ts b/arkui-plugins/ui-syntax-plugins/rules/custom-dialog-missing-controller.ts index d35cf99f296b9971af47bdca044a45079d0b72c7..806477eeb408b1c6fac352a7a48794b1122219bf 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/custom-dialog-missing-controller.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/custom-dialog-missing-controller.ts @@ -27,14 +27,14 @@ class CustomDialogMissingControllerRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.checkMissingController(node); } // Check if the @CustomDialog-decorated struct contains a property of type CustomDialogController - private checkMissingController(node: arkts.StructDeclaration): void { + private checkMissingController(node: arkts.ETSStructDeclaration): void { const customDialogDecorator = getAnnotationUsage(node, PresetDecorators.CUSTOM_DIALOG); if (!customDialogDecorator) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/entry-localstorage-check.ts b/arkui-plugins/ui-syntax-plugins/rules/entry-localstorage-check.ts index 7fb2892535ddafccfbf5fbb8d8cbc08c187d4586..a8b0f37c47a1d0bd7c10de8fca69e6ef06231f58 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/entry-localstorage-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/entry-localstorage-check.ts @@ -25,13 +25,13 @@ class EntryLocalStorageCheckRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.checkLocalStorageLink(node); } - private checkLocalStorageLink(node: arkts.StructDeclaration): void { + private checkLocalStorageLink(node: arkts.ETSStructDeclaration): void { // Check if @Entry decorator exists with parameter const entryDecorator = getAnnotationUsage(node, PresetDecorators.ENTRY); const isStorageUsed = entryDecorator && entryDecorator.properties[0]; diff --git a/arkui-plugins/ui-syntax-plugins/rules/entry-struct-no-export.ts b/arkui-plugins/ui-syntax-plugins/rules/entry-struct-no-export.ts index 0bd71b7c732f221a3c47bda827c3165e3d20080d..0034146a4262068f93708d74728d365af366724e 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/entry-struct-no-export.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/entry-struct-no-export.ts @@ -26,7 +26,7 @@ class EntryStructNoExportRule extends AbstractUISyntaxRule { public parsed(node: arkts.AstNode): void { // Check if the current node is a schema declaration - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } // Get the usage of the @Entry decorator diff --git a/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts b/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts index c0b9181e4a4de46ff022adfd40d0b7db2bfb62e6..2ea7f5e815cd556c9409568647826034afe21cd4 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts @@ -24,7 +24,7 @@ class MainPagesEntryCheckRule extends AbstractUISyntaxRule { }; } public parsed(node: arkts.AstNode): void { - if (!arkts.isEtsScript(node) || node.isNamespace) { + if (!arkts.isETSModule(node) || node.isNamespace) { return; } const currentFilePath = getCurrentFilePath(node); @@ -40,7 +40,7 @@ class MainPagesEntryCheckRule extends AbstractUISyntaxRule { // Traverse all child nodes of the Program for (const child of node.getChildren()) { // Check if it's of type StructDeclaration - if (arkts.isStructDeclaration(child)) { + if (arkts.isETSStructDeclaration(child)) { if (!firstStructDeclaration) { firstStructDeclaration = child.definition.ident; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/monitor-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/monitor-decorator-check.ts index 4074a1724565be4fa891609f8cf3e592b3214d7f..dfba70b12819229e036b4e165b98ee68d32dffc3 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/monitor-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/monitor-decorator-check.ts @@ -32,7 +32,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isClassDeclaration(node) && !arkts.isStructDeclaration(node)) { + if (!arkts.isClassDeclaration(node) && !arkts.isETSStructDeclaration(node)) { return; } @@ -41,7 +41,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { this.checkMonitorInClass(node, monitorDecorator); } - if (monitorDecorator && arkts.isStructDeclaration(node)) { + if (monitorDecorator && arkts.isETSStructDeclaration(node)) { this.checkMonitorInStruct(node, monitorDecorator); } this.checkDecorateMethod(node); @@ -86,7 +86,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { } private checkMonitorInStruct( - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, monitorDecorator: arkts.AnnotationUsage | undefined, ): void { if (!monitorDecorator) { @@ -120,7 +120,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { } } - private checkDecorator(node: arkts.ClassDeclaration | arkts.StructDeclaration, decoratorName: string): boolean { + private checkDecorator(node: arkts.ClassDeclaration | arkts.ETSStructDeclaration, decoratorName: string): boolean { return node.definition?.annotations?.some( annotation => annotation.expr && arkts.isIdentifier(annotation.expr) && annotation.expr?.name === decoratorName @@ -128,7 +128,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { } private checkMonitorUsage( - node: arkts.ClassDeclaration | arkts.StructDeclaration + node: arkts.ClassDeclaration | arkts.ETSStructDeclaration ): arkts.AnnotationUsage | undefined { let monitorUsage: arkts.AnnotationUsage | undefined; @@ -148,7 +148,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { } private getLocalMonitorUsed(body: arkts.MethodDefinition): arkts.AnnotationUsage | undefined { - const localMonitorUsed = body.scriptFunction.annotations?.find( + const localMonitorUsed = body.function!.annotations?.find( annotation => annotation.expr && arkts.isIdentifier(annotation.expr) && annotation.expr.name === PresetDecorators.MONITOR ); @@ -156,7 +156,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { } private checkConflictingDecorators(body: arkts.MethodDefinition, localMonitorUsed: arkts.AnnotationUsage): boolean { - const conflictingDecorators = body.scriptFunction.annotations?.filter( + const conflictingDecorators = body.function!.annotations?.filter( annotation => annotation.expr && arkts.isIdentifier(annotation.expr) && annotation.expr.name !== PresetDecorators.MONITOR ); @@ -185,7 +185,7 @@ class MonitorDecoratorCheckRule extends AbstractUISyntaxRule { }); } - private checkDecorateMethod(node: arkts.ClassDeclaration | arkts.StructDeclaration): void { + private checkDecorateMethod(node: arkts.ClassDeclaration | arkts.ETSStructDeclaration): void { // Check if @Monitor is used on a property (which is not allowed) node.definition?.body.forEach((body) => { if (!arkts.isClassProperty(body)) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/nested-relationship.ts b/arkui-plugins/ui-syntax-plugins/rules/nested-relationship.ts index 2f4ee91e01762d81c4c699c03f828bd941691d48..0f570d596112d7372dbf69650655c05253074c88 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/nested-relationship.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/nested-relationship.ts @@ -34,7 +34,7 @@ class NestedRelationshipRule extends AbstractUISyntaxRule { delegateParentComponent: `The '{{componentName}}' component can only be nested in the '{{parentComponentList}}' parent component.`, }; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.checkValidParentComponent(node); this.checkValidChildComponent(node); this.checkSingleChildComponent(node); diff --git a/arkui-plugins/ui-syntax-plugins/rules/nested-reuse-component-check.ts b/arkui-plugins/ui-syntax-plugins/rules/nested-reuse-component-check.ts index 62f109253ea5b5f661f2f4e4fb3f985784a20298..1d2ee07de3a6c2b9f22de94304c13d2ccc089cbd 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/nested-reuse-component-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/nested-reuse-component-check.ts @@ -35,7 +35,7 @@ class NestedReuseComponentCheckRule extends AbstractUISyntaxRule { this.reusableStructName = []; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.initStructName(node); this.checkNestedReuseComponent(node); this.checkNoReusableV1InReusableV2(node); @@ -48,7 +48,7 @@ class NestedReuseComponentCheckRule extends AbstractUISyntaxRule { //Go through all the children of Program for (const childNode of node.getChildren()) { // Check whether the type is struct - if (!arkts.isStructDeclaration(childNode)) { + if (!arkts.isETSStructDeclaration(childNode)) { continue; } // Get a list of annotations @@ -126,7 +126,7 @@ class NestedReuseComponentCheckRule extends AbstractUISyntaxRule { if (this.reusableStructName.includes(node.expression.name)) { // Traverse upwards to find the custom component. let struceNode: arkts.AstNode = node; - while (!arkts.isStructDeclaration(struceNode)) { + while (!arkts.isETSStructDeclaration(struceNode)) { if (!struceNode.parent) { return; } @@ -174,7 +174,7 @@ class NestedReuseComponentCheckRule extends AbstractUISyntaxRule { // Traverse upwards to find the custom component. let struceNode: arkts.AstNode = node; let hasReportedError = false; - while (!arkts.isStructDeclaration(struceNode)) { + while (!arkts.isETSStructDeclaration(struceNode)) { if (!struceNode.parent) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/no-child-in-button.ts b/arkui-plugins/ui-syntax-plugins/rules/no-child-in-button.ts index 8673700ac2b586656c340f7038db807562f428c6..42a6b8b75047f5cb2389578f683c4d977f7d04eb 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/no-child-in-button.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/no-child-in-button.ts @@ -58,7 +58,7 @@ class NoChildInButtonRule extends AbstractUISyntaxRule { let isInStruct = false; let isInBuild = false; while (arkts.nodeType(parentNode) !== arkts.Es2pandaAstNodeType.AST_NODE_TYPE_ETS_MODULE) { - if (arkts.isStructDeclaration(parentNode)) { + if (arkts.isETSStructDeclaration(parentNode)) { isInStruct = true; } if (arkts.isScriptFunction(parentNode) && parentNode.id?.name === 'build') { diff --git a/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-entry.ts b/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-entry.ts index 0c2f219261e576dbea50ed4e35bbbaec47dcdbac..eb35fa65a67987231e4d6fc2834d378a9621dffe 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-entry.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-entry.ts @@ -32,8 +32,8 @@ class NoDuplicateEntryRule extends AbstractUISyntaxRule { this.entryDecoratorUsageIndex = 1; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isStructDeclaration(node)) { + public parsed(node: arkts.ETSStructDeclaration): void { + if (!arkts.isETSStructDeclaration(node)) { return; } let entryDecoratorUsage = getAnnotationUsage(node, PresetDecorators.ENTRY); diff --git a/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-preview.ts b/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-preview.ts index 4cd553402652f69c1383b0f3f05055deae9e07e3..fd0e0213c1dcb1f6fb9a90b8ac5d289732d88a47 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-preview.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/no-duplicate-preview.ts @@ -32,8 +32,8 @@ class NoDuplicatePreviewRule extends AbstractUISyntaxRule { this.previewDecoratorUsageIndex = 10; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isStructDeclaration(node)) { + public parsed(node: arkts.ETSStructDeclaration): void { + if (!arkts.isETSStructDeclaration(node)) { return; } const previewDecoratorUsage = getAnnotationUsage( diff --git a/arkui-plugins/ui-syntax-plugins/rules/no-prop-link-objectlink-in-entry.ts b/arkui-plugins/ui-syntax-plugins/rules/no-prop-link-objectlink-in-entry.ts index 5cfe3351c7a85334bf22dc4acde555dee545eab9..dba126d0fca692f94e0d370ea367df64cc26cf58 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/no-prop-link-objectlink-in-entry.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/no-prop-link-objectlink-in-entry.ts @@ -26,13 +26,13 @@ class NoPropLinkObjectLinkInEntryRule extends AbstractUISyntaxRule { }; } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.checkNoPropLinkOrObjectLinkInEntry(node); } - private checkNoPropLinkOrObjectLinkInEntry(node: arkts.StructDeclaration): void { + private checkNoPropLinkOrObjectLinkInEntry(node: arkts.ETSStructDeclaration): void { // Check if the struct has the @Entry decorator const isEntryComponent = !!getAnnotationUsage(node, PresetDecorators.ENTRY); if (!node.definition.ident || !arkts.isIdentifier(node.definition.ident)) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/no-same-as-built-in-attribute.ts b/arkui-plugins/ui-syntax-plugins/rules/no-same-as-built-in-attribute.ts index 5940191f68b5f240a1b74058874dd0a235291b64..dd9d275febacbe670e2e6068bf44f80c23530ed3 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/no-same-as-built-in-attribute.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/no-same-as-built-in-attribute.ts @@ -25,7 +25,7 @@ class NoSameAsBuiltInAttributeRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } if (!node.definition) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/observedV2-trace-usage-validation.ts b/arkui-plugins/ui-syntax-plugins/rules/observedV2-trace-usage-validation.ts index c8a7ae084556bdd107e7b4e9a01bee8b1f7d0db8..f5f491e2d2b64d9305bebe8249c24118113026e7 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/observedV2-trace-usage-validation.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/observedV2-trace-usage-validation.ts @@ -77,7 +77,7 @@ class ObservedV2TraceUsageValidationRule extends AbstractUISyntaxRule { private tracePropertyRule( currentNode: arkts.AstNode, traceDecorator: arkts.AnnotationUsage): void { - if (arkts.isStructDeclaration(currentNode)) { + if (arkts.isETSStructDeclaration(currentNode)) { this.reportTraceDecoratorError(traceDecorator); } else if (arkts.isClassDeclaration(currentNode) && currentNode.definition) { const observedDecorator = this.getObservedDecorator(currentNode); @@ -162,7 +162,7 @@ class ObservedV2TraceUsageValidationRule extends AbstractUISyntaxRule { private validateTraceDecoratorUsage(node: arkts.AstNode): void { let currentNode = node; - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { // Check whether the current custom component is decorated by the @ObservedV2 decorator const observedV2Decorator = getAnnotationUsage(node, PresetDecorators.OBSERVED_V2); const traceDecorator = getAnnotationUsage(node, PresetDecorators.TRACE); @@ -189,12 +189,12 @@ class ObservedV2TraceUsageValidationRule extends AbstractUISyntaxRule { } if (arkts.isMethodDefinition(node) && this.isInClassDeclaration(currentNode)) { // Check that @Trace is in the correct location - const traceDecorator = findDecorator(node.scriptFunction, PresetDecorators.TRACE); + const traceDecorator = findDecorator(node.function!, PresetDecorators.TRACE); if (traceDecorator) { this.reportTraceMemberVariableError(traceDecorator); } } else if (arkts.isMethodDefinition(node) && !this.isInClassDeclaration(currentNode)) { - const traceDecorator = findDecorator(node.scriptFunction, PresetDecorators.TRACE); + const traceDecorator = findDecorator(node.function!, PresetDecorators.TRACE); if (traceDecorator) { this.reportTraceDecoratorError(traceDecorator); } @@ -207,7 +207,7 @@ class ObservedV2TraceUsageValidationRule extends AbstractUISyntaxRule { const traceDecorator = findDecorator(node, PresetDecorators.TRACE); if (traceDecorator) { // Iterate up the parent node to check whether it is a class or a custom component - while (!arkts.isStructDeclaration(currentNode) && !arkts.isClassDeclaration(currentNode)) { + while (!arkts.isETSStructDeclaration(currentNode) && !arkts.isClassDeclaration(currentNode)) { if (!currentNode.parent) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/old-new-decorator-mix-use-check.ts b/arkui-plugins/ui-syntax-plugins/rules/old-new-decorator-mix-use-check.ts index 704eb038b5636ace1c45682d633f3401ffe30f8e..9f094f346c8cc4ac6ce9649eb259ed150d4bfc2d 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/old-new-decorator-mix-use-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/old-new-decorator-mix-use-check.ts @@ -47,8 +47,8 @@ class OldNewDecoratorMixUseCheckRule extends AbstractUISyntaxRule { oldAndNewDecoratorsMixUse: `The '@{{decoratorName}}' annotation can only be used in a 'struct' decorated with '@{{component}}'.`, }; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isStructDeclaration(node)) { + public parsed(node: arkts.ETSStructDeclaration): void { + if (!arkts.isETSStructDeclaration(node)) { return; } // Gets the decorator version of a custom component @@ -108,7 +108,7 @@ class OldNewDecoratorMixUseCheckRule extends AbstractUISyntaxRule { } private reportErrorAndAddDecorator( - structNode: arkts.StructDeclaration, + structNode: arkts.ETSStructDeclaration, errorDecorator: arkts.AnnotationUsage, ): void { let propertyDecoratorName = getAnnotationName(errorDecorator); diff --git a/arkui-plugins/ui-syntax-plugins/rules/once-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/once-decorator-check.ts index 85e8bd8cf2f3ac63683792b8eccf039a19b01d33..2e8a0163daa7a914e9a7c9d6d37096e62b71f785 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/once-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/once-decorator-check.ts @@ -32,7 +32,7 @@ class OnceDecoratorCheckRule extends AbstractUISyntaxRule { this.validateOnlyInStruct(node); this.validateOnlyOnProperty(node); - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { this.validateDecorator(node, onceDecorator); } } @@ -45,7 +45,7 @@ class OnceDecoratorCheckRule extends AbstractUISyntaxRule { } if (arkts.isMethodDefinition(member)) { - this.validateOnceDecoratorUsage(member.scriptFunction, this.messages.invalidNOtInStruct); + this.validateOnceDecoratorUsage(member.function!, this.messages.invalidNOtInStruct); } }); return; @@ -94,7 +94,7 @@ class OnceDecoratorCheckRule extends AbstractUISyntaxRule { } private validateDecorator( - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, onceDecorator: arkts.AnnotationUsage | undefined, ): void { node.definition?.body.forEach(body => { diff --git a/arkui-plugins/ui-syntax-plugins/rules/one-decorator-on-function-method.ts b/arkui-plugins/ui-syntax-plugins/rules/one-decorator-on-function-method.ts index f31cfec4ad1e92cf52c584d8b9562a9f4d741bf1..e32ae5430b5b18423301f6e5c43858172a46f0e1 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/one-decorator-on-function-method.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/one-decorator-on-function-method.ts @@ -30,7 +30,7 @@ class OneDecoratorOnFunctionMethodRule extends AbstractUISyntaxRule { public parsed(node: arkts.AstNode): void { // If the node is not an ETS script, it is returned directly - if (!arkts.isEtsScript(node)) { + if (!arkts.isETSModule(node)) { return; } this.validateFunctionDecorator(node); @@ -49,8 +49,8 @@ class OneDecoratorOnFunctionMethodRule extends AbstractUISyntaxRule { } // @AnimatableExtend decorators can only be used with functions with this parameter. const animatableExtendDecorator = this.findDecorator(annotations, PresetDecorators.ANIMATABLE_EXTEND); - if (arkts.isScriptFunction(statement.scriptFunction) && animatableExtendDecorator) { - const member = statement.scriptFunction; + if (arkts.isScriptFunction(statement.function!) && animatableExtendDecorator) { + const member = statement.function!; if (this.hasThisParameter(member)) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/property-type.ts b/arkui-plugins/ui-syntax-plugins/rules/property-type.ts index 04b2b3da1e3dc526bb53196a3eef02b93d94441e..84c5dc9c9cc1c8df9b3ab45b210185d7f186cda3 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/property-type.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/property-type.ts @@ -324,7 +324,7 @@ class PropertyTypeRule extends AbstractUISyntaxRule { } node.getChildren().forEach((member) => { // Only the situation within the component is judged - if (!arkts.isStructDeclaration(member) || !member.definition.ident) { + if (!arkts.isETSStructDeclaration(member) || !member.definition.ident) { return; } this.getCurrentStructBuilderMethodName(member); @@ -389,13 +389,13 @@ class PropertyTypeRule extends AbstractUISyntaxRule { return; } node.getChildren().forEach((member) => { - if (arkts.isFunctionDeclaration(member) && member.scriptFunction.id?.name) { + if (arkts.isFunctionDeclaration(member) && member.function!.id?.name) { const hasBuilderDecorator = findDecorator(member, PresetDecorators.BUILDER); if (hasBuilderDecorator) { - this.builderFunctionName.push(member.scriptFunction.id?.name); + this.builderFunctionName.push(member.function!.id?.name); } } - if (arkts.isStructDeclaration(member) && member.definition.ident) { + if (arkts.isETSStructDeclaration(member) && member.definition.ident) { let structName = member.definition.ident.name; this.structStaticMethodsMap.set(structName, new Set()); member.definition.body.forEach((item) => { @@ -409,28 +409,28 @@ class PropertyTypeRule extends AbstractUISyntaxRule { item: arkts.AstNode, structName: string ): void { - if (!arkts.isMethodDefinition(item) || !item.scriptFunction.id || !item.isStatic) { + if (!arkts.isMethodDefinition(item) || !item.function!.id || !item.isStatic) { return; } - const hasBuilderDecorator = findDecorator(item.scriptFunction, PresetDecorators.BUILDER); + const hasBuilderDecorator = findDecorator(item.function!, PresetDecorators.BUILDER); // judgment static method - if (hasBuilderDecorator && arkts.isIdentifier(item.scriptFunction.id) && item.isStatic) { - const methodName = item.scriptFunction.id.name; + if (hasBuilderDecorator && arkts.isIdentifier(item.function!.id) && item.isStatic) { + const methodName = item.function!.id.name; this.structStaticMethodsMap.get(structName)?.add(methodName); } } private getCurrentStructBuilderMethodName( - node: arkts.StructDeclaration + node: arkts.ETSStructDeclaration ): void { node.definition?.body?.forEach((item) => { - if (!arkts.isMethodDefinition(item) || !item.scriptFunction.id) { + if (!arkts.isMethodDefinition(item) || !item.function!.id) { return; } - const builderDecorator = findDecorator(item.scriptFunction, PresetDecorators.BUILDER); + const builderDecorator = findDecorator(item.function!, PresetDecorators.BUILDER); // judgment static method - if (builderDecorator && arkts.isIdentifier(item.scriptFunction.id) && !item.isStatic) { - this.currentStructBuilderMethodName.push(item.scriptFunction.id.name); + if (builderDecorator && arkts.isIdentifier(item.function!.id) && !item.isStatic) { + this.currentStructBuilderMethodName.push(item.function!.id.name); } }); } diff --git a/arkui-plugins/ui-syntax-plugins/rules/require-decorator-regular.ts b/arkui-plugins/ui-syntax-plugins/rules/require-decorator-regular.ts index dd3abf59c2bf2f2f77c28ff6fc4521a3603f6bdf..b6e4b508958195a3de8903ae5497a101659dcf2c 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/require-decorator-regular.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/require-decorator-regular.ts @@ -25,13 +25,13 @@ class RequireDecoratorRegularRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.checkRequireDecorator(node); } - private checkRequireDecorator(node: arkts.StructDeclaration): void { + private checkRequireDecorator(node: arkts.ETSStructDeclaration): void { node.definition.body.forEach(member => { if (!arkts.isClassProperty(member)) { return; diff --git a/arkui-plugins/ui-syntax-plugins/rules/reusable-component-in-V2-check.ts b/arkui-plugins/ui-syntax-plugins/rules/reusable-component-in-V2-check.ts index 57901a88dfde794231e4ce14ecf7e125cfe9935c..c93fe3ca957cee36c257c356bc5e793ae6ce8b3f 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/reusable-component-in-V2-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/reusable-component-in-V2-check.ts @@ -29,7 +29,7 @@ class ReusableComponentInV2CheckRule extends AbstractUISyntaxRule { public beforeTransform(): void { this.reusableStructName = []; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.initStructName(node); this.checkNoReusableV1InComponentV2(node); } @@ -41,7 +41,7 @@ class ReusableComponentInV2CheckRule extends AbstractUISyntaxRule { //Go through all the children of Program for (const childNode of node.getChildren()) { // Check whether the type is struct - if (!arkts.isStructDeclaration(childNode)) { + if (!arkts.isETSStructDeclaration(childNode)) { continue; } const reusableV1Decorator = getAnnotationUsage(childNode, PresetDecorators.REUSABLE_V1); @@ -59,7 +59,7 @@ class ReusableComponentInV2CheckRule extends AbstractUISyntaxRule { if (this.reusableStructName.includes(node.expression.name)) { // Traverse upwards to find the custom component. let structNode: arkts.AstNode = node; - while (!arkts.isStructDeclaration(structNode)) { + while (!arkts.isETSStructDeclaration(structNode)) { if (!structNode.parent) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/reusableV2-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/reusableV2-decorator-check.ts index 24a7ca87ced670eeea904ec783d851b98cdb357d..8f75eacd6c00039f244f26f914a91be8a161401f 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/reusableV2-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/reusableV2-decorator-check.ts @@ -26,7 +26,7 @@ class ReusableV2DecoratorCheckRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } if (!node.definition) { @@ -66,7 +66,7 @@ class ReusableV2DecoratorCheckRule extends AbstractUISyntaxRule { } private reportInvalidDecoratorUsage( - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, structNode: arkts.Identifier | undefined, ): void { if (!structNode || !node) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/reuse-attribute-check.ts b/arkui-plugins/ui-syntax-plugins/rules/reuse-attribute-check.ts index 5c60e83b6f6da95069420fdb7557e2027c835468..ead40e0b9c009704f3413b1bd9246f828c6260dd 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/reuse-attribute-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/reuse-attribute-check.ts @@ -45,7 +45,7 @@ class ReuseAttributeCheckRule extends AbstractUISyntaxRule { //Go through all the children of Program for (const childNode of node.getChildren()) { // Check whether the type is struct - if (!arkts.isStructDeclaration(childNode)) { + if (!arkts.isETSStructDeclaration(childNode)) { continue; } // Check that the current component has @ComponentV2 and @ReusableV2 decorators diff --git a/arkui-plugins/ui-syntax-plugins/rules/specific-component-children.ts b/arkui-plugins/ui-syntax-plugins/rules/specific-component-children.ts index aace72ff3493ab6e4a8d4b765f64dc0282270519..e1011366bd1eae3a741438c9aa574a5c22a1ec4c 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/specific-component-children.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/specific-component-children.ts @@ -32,7 +32,7 @@ class SpecificComponentChildrenRule extends AbstractUISyntaxRule { }; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { if (!arkts.isCallExpression(node) || !node.expression) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/struct-missing-decorator.ts b/arkui-plugins/ui-syntax-plugins/rules/struct-missing-decorator.ts index 11b48a21938957acdad946cfc2bf4c112ea0236a..39cc9232d06e70a6835a238fdc97e7ae4476d426 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/struct-missing-decorator.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/struct-missing-decorator.ts @@ -25,7 +25,7 @@ class StructMissingDecoratorRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } if (!node.definition) { @@ -51,7 +51,7 @@ class StructMissingDecoratorRule extends AbstractUISyntaxRule { } } - private hasDecorator(node: arkts.StructDeclaration, decorator: string): boolean { + private hasDecorator(node: arkts.ETSStructDeclaration, decorator: string): boolean { return !!getAnnotationUsage(node, decorator); } } diff --git a/arkui-plugins/ui-syntax-plugins/rules/struct-no-extends.ts b/arkui-plugins/ui-syntax-plugins/rules/struct-no-extends.ts index 12945ee48719f9628d9f606b52d2483e71268369..8f07c5f7aef1685e5f7685454c77f1fb3c7e8d7b 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/struct-no-extends.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/struct-no-extends.ts @@ -22,8 +22,8 @@ class StructNoExtendsRule extends AbstractUISyntaxRule { structNoExtends: `Structs are not allowed to inherit from classes or implement interfaces.`, }; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isStructDeclaration(node) || !node.definition.ident) { + public parsed(node: arkts.ETSStructDeclaration): void { + if (!arkts.isETSStructDeclaration(node) || !node.definition.ident) { return; } const hasSuperClass: boolean = node.definition.super !== undefined; diff --git a/arkui-plugins/ui-syntax-plugins/rules/struct-property-decorator.ts b/arkui-plugins/ui-syntax-plugins/rules/struct-property-decorator.ts index caac4a335fb730ccf980dfb3f0f1651ab226834c..f20ec3dbedf37a36024989803d76a1d3125dcb85 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/struct-property-decorator.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/struct-property-decorator.ts @@ -38,7 +38,7 @@ class StructPropertyDecoratorRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.checkInvalidStaticPropertyDecorations(node); @@ -53,7 +53,7 @@ class StructPropertyDecoratorRule extends AbstractUISyntaxRule { ); } - private checkInvalidStaticPropertyDecorations(node: arkts.StructDeclaration,): void { + private checkInvalidStaticPropertyDecorations(node: arkts.ETSStructDeclaration,): void { node.definition.body.forEach((member) => { // Errors are reported when the node type is ClassProperty, if (arkts.isClassProperty(member)) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/track-decorator-check.ts b/arkui-plugins/ui-syntax-plugins/rules/track-decorator-check.ts index e7ab4ec8da51785ea1889a3ec2d4b9b590aebf86..32c62b2f9e83da8c28f1da9a9411d8f2a8f9b87e 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/track-decorator-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/track-decorator-check.ts @@ -32,7 +32,7 @@ class TrackDecoratorCheckRule extends AbstractUISyntaxRule { arkts.isTSTypeAliasDeclaration(node)) { this.reportInvalidTrackDecoratorUsage(node); } - if (arkts.isStructDeclaration(node)) { + if (arkts.isETSStructDeclaration(node)) { this.checkInvalidTrackAnnotations(node); } // Check if the current node is a class declaration @@ -51,7 +51,7 @@ class TrackDecoratorCheckRule extends AbstractUISyntaxRule { } } - private checkInvalidTrackAnnotations(node: arkts.StructDeclaration): void { + private checkInvalidTrackAnnotations(node: arkts.ETSStructDeclaration): void { const trackAnnotation = getAnnotationUsage(node, PresetDecorators.TRACK); if (trackAnnotation) { this.reportInvalidTarget(trackAnnotation); @@ -68,7 +68,7 @@ class TrackDecoratorCheckRule extends AbstractUISyntaxRule { } // Check whether this is the method if (arkts.isMethodDefinition(member)) { - const trackDecorator = findDecorator(member.scriptFunction, PresetDecorators.TRACK); + const trackDecorator = findDecorator(member.function!, PresetDecorators.TRACK); // If the method is decorated with @Track, an error is reported immediately if (trackDecorator) { this.reportInvalidTarget(trackDecorator); @@ -93,7 +93,7 @@ class TrackDecoratorCheckRule extends AbstractUISyntaxRule { } // Check whether this is the method if (arkts.isMethodDefinition(member)) { - const trackDecorator = findDecorator(member.scriptFunction, PresetDecorators.TRACK); + const trackDecorator = findDecorator(member.function!, PresetDecorators.TRACK); // If the method is decorated with @Track, an error is reported immediately if (trackDecorator) { this.reportInvalidTarget(trackDecorator); diff --git a/arkui-plugins/ui-syntax-plugins/rules/ui-consistent-check.ts b/arkui-plugins/ui-syntax-plugins/rules/ui-consistent-check.ts index 45d3705217922a485c22d72521651691c1b1c05e..4b47ffecc6952f7907b74fb1afcf2d20eb4ae159 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/ui-consistent-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/ui-consistent-check.ts @@ -41,7 +41,7 @@ class UiConsistentCheckRule extends AbstractUISyntaxRule { }; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { // Specific Attributes: Check the VP units this.checkVpUnit(node); // Specific attributes: Check the VP and PX units @@ -94,7 +94,7 @@ class UiConsistentCheckRule extends AbstractUISyntaxRule { } let curNode = node; try { - while (!arkts.isStructDeclaration(curNode)) { + while (!arkts.isETSStructDeclaration(curNode)) { if (!curNode.parent) { return false; } diff --git a/arkui-plugins/ui-syntax-plugins/rules/validate-build-in-struct.ts b/arkui-plugins/ui-syntax-plugins/rules/validate-build-in-struct.ts index 0388d347889eff2bc920a217188f436885a721e7..1df278abd0bc528a2bc86d0af5270d8c09106901 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/validate-build-in-struct.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/validate-build-in-struct.ts @@ -31,7 +31,7 @@ class ValidateBuildInStructRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } let buildFunctionCount: number = BUILD_FUNCTION_COUNT_INI; @@ -39,7 +39,7 @@ class ValidateBuildInStructRule extends AbstractUISyntaxRule { } private validateBuild( - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, buildFunctionCount: number ): void { node.definition.body.forEach((member) => { @@ -59,7 +59,7 @@ class ValidateBuildInStructRule extends AbstractUISyntaxRule { // rule1: Check if the build function contains arguments and report an error private validateBuildFunctionParameters(buildFunction: arkts.MethodDefinition): void { - const paramsNodes = buildFunction.scriptFunction.params; + const paramsNodes = buildFunction.function!.params; if (paramsNodes.length > NOT_PARAM_LENGTH) { paramsNodes.forEach((param) => { if (arkts.isEtsParameterExpression(param)) { @@ -74,7 +74,7 @@ class ValidateBuildInStructRule extends AbstractUISyntaxRule { member: arkts.MethodDefinition, ): void { if (buildFunctionCount > BUILD_FUNCTION_COUNT) { - const buildNode = member.scriptFunction.id; + const buildNode = member.function!.id; if (!buildNode) { return; } @@ -100,11 +100,11 @@ class ValidateBuildInStructRule extends AbstractUISyntaxRule { } private validateConstructorForBuildFunction( - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, member: arkts.MethodDefinition, buildFunctionCount: number, ): void { - const blockStatement = member.scriptFunction.body; + const blockStatement = member.function!.body; if (!blockStatement || !arkts.isBlockStatement(blockStatement)) { return; } @@ -136,7 +136,7 @@ class ValidateBuildInStructRule extends AbstractUISyntaxRule { private reportMissingBuildInStruct( structName: arkts.Identifier | undefined, - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, ): void { if (!structName) { return; diff --git a/arkui-plugins/ui-syntax-plugins/rules/validate-decorator-target.ts b/arkui-plugins/ui-syntax-plugins/rules/validate-decorator-target.ts index d48cb7dd8122e6c012e0f5663f35ffc53e0eaf1b..4bdb2cf784f9b104650c7ad68297a99a2f543490 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/validate-decorator-target.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/validate-decorator-target.ts @@ -54,7 +54,7 @@ class ValidateDecoratorTargetRule extends AbstractUISyntaxRule { public parsed(node: arkts.AstNode): void { this.validateDecoratorPropertyOnly(node); - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { this.validateDecoratorStructOnly(node); } } @@ -94,7 +94,7 @@ class ValidateDecoratorTargetRule extends AbstractUISyntaxRule { if (arkts.isMethodDefinition(node) && (node.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_GET || node.kind === arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_SET)) { - node.scriptFunction.annotations.forEach((annotation) => { + node.function!.annotations.forEach((annotation) => { this.validateDecorator(annotation, structOnlyDecorators, this.messages.decoratorOnlyWithStruct); }); } diff --git a/arkui-plugins/ui-syntax-plugins/rules/variable-initialization-via-component-constructor.ts b/arkui-plugins/ui-syntax-plugins/rules/variable-initialization-via-component-constructor.ts index 29c7209c60e4cd87849d9c913e9831d1361e375e..6059671dcbc8c2eafcb972ef3c5516ea54cf7ae0 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/variable-initialization-via-component-constructor.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/variable-initialization-via-component-constructor.ts @@ -49,7 +49,7 @@ class VariableInitializationViaComponentConstructorRule extends AbstractUISyntax this.cannotInitMap = new Map(); } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.initMap(node); this.checkMustInitialize(node); this.checkCannotInitialize(node); @@ -100,7 +100,7 @@ class VariableInitializationViaComponentConstructorRule extends AbstractUISyntax return; } node.getChildren().forEach((member) => { - if (!arkts.isStructDeclaration(member)) { + if (!arkts.isETSStructDeclaration(member)) { return; } if (!member.definition || !member.definition.ident || !arkts.isIdentifier(member.definition.ident)) { diff --git a/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts b/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts index bd3ea010b327bf21467b8cea11d6175dcf2138d2..acd08b2b99f8bc23b1f1b66c19fe8953f482bc76 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts @@ -26,7 +26,7 @@ class WatchDecoratorFunctionRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } // Get all method names @@ -57,7 +57,7 @@ class WatchDecoratorFunctionRule extends AbstractUISyntaxRule { } // Gets the names of all methods in the struct - private getMethodNames(node: arkts.StructDeclaration): string[] { + private getMethodNames(node: arkts.ETSStructDeclaration): string[] { const methodNames: string[] = []; node.definition.body.forEach((member) => { if (arkts.isMethodDefinition(member) && arkts.isIdentifier(member.name)) { @@ -70,7 +70,7 @@ class WatchDecoratorFunctionRule extends AbstractUISyntaxRule { return methodNames; } - private getPrivateNames(node: arkts.StructDeclaration): string[] { + private getPrivateNames(node: arkts.ETSStructDeclaration): string[] { const privateNames: string[] = []; node.definition.body.forEach((member) => { if (arkts.isClassProperty(member) && isPrivateClassProperty(member)) { @@ -84,7 +84,7 @@ class WatchDecoratorFunctionRule extends AbstractUISyntaxRule { } private validateWatch( - node: arkts.StructDeclaration, + node: arkts.ETSStructDeclaration, methodNames: string[], privateNames: string[] ): void { diff --git a/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-regular.ts b/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-regular.ts index fc2c30f3999f355d761f7a7d37193249fad67eab..5014c87450c4fe609d6d982e37cb15f2dd560dfc 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-regular.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-regular.ts @@ -27,13 +27,13 @@ class WatchDecoratorRegularRule extends AbstractUISyntaxRule { } public parsed(node: arkts.AstNode): void { - if (!arkts.isStructDeclaration(node)) { + if (!arkts.isETSStructDeclaration(node)) { return; } this.validateWatchDecorator(node); } - private validateWatchDecorator(node: arkts.StructDeclaration): void { + private validateWatchDecorator(node: arkts.ETSStructDeclaration): void { node.definition.body.forEach(member => { if (!arkts.isClassProperty(member)) { return; diff --git a/arkui-plugins/ui-syntax-plugins/rules/wrap-builder-check.ts b/arkui-plugins/ui-syntax-plugins/rules/wrap-builder-check.ts index a8f2da56f9eebd4c64c0842de3d10a14da6bc8a5..02d9b7d1532c197fbdca0eaef79c530d6d0b295c 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/wrap-builder-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/wrap-builder-check.ts @@ -30,14 +30,14 @@ class StructNoExtendsRule extends AbstractUISyntaxRule { this.builderFunctionNames = []; } - public parsed(node: arkts.StructDeclaration): void { + public parsed(node: arkts.ETSStructDeclaration): void { this.collectBuilderFunctions(node); this.validateWrapBuilderInIdentifier(node); } // Collect all the function names that are decorated with @Builder private collectBuilderFunctions(node: arkts.AstNode): void { - if (!arkts.isEtsScript(node)) { + if (!arkts.isETSModule(node)) { return; } node.statements.forEach((statement) => { @@ -48,7 +48,7 @@ class StructNoExtendsRule extends AbstractUISyntaxRule { if (!buildDecoratorUsage) { return; } - const functionName = statement.scriptFunction.id?.name; + const functionName = statement.function!.id?.name; if (!functionName || functionName === '' || this.builderFunctionNames.includes(functionName)) { return; } diff --git a/arkui-plugins/ui-syntax-plugins/utils/index.ts b/arkui-plugins/ui-syntax-plugins/utils/index.ts index 0e3f34341be809724e5b4355f51a60b3c9707c88..07b409d5d8ee8e68ed7ddef1246d93391ba0df31 100644 --- a/arkui-plugins/ui-syntax-plugins/utils/index.ts +++ b/arkui-plugins/ui-syntax-plugins/utils/index.ts @@ -152,7 +152,7 @@ export function getAnnotationName(annotation: arkts.AnnotationUsage): string { } export function getAnnotationUsage( - declaration: arkts.StructDeclaration, + declaration: arkts.ETSStructDeclaration, annotationName: string ): arkts.AnnotationUsage | undefined { return declaration.definition.annotations.find(