From 7f26291e0e3ae574cf96dd619c361e5f539c7f47 Mon Sep 17 00:00:00 2001 From: Yuxin Feng Date: Mon, 9 Jun 2025 18:29:04 +0800 Subject: [PATCH] uiplugin Navigation transform Signed-off-by: Yuxin Feng Change-Id: Ifa06587f1f7d9af9a08c0032e61927fb97d5840e --- arkui-plugins/common/plugin-context.ts | 3 + arkui-plugins/common/predefines.ts | 3 + arkui-plugins/test/utils/plugin-tester.ts | 4 +- .../test/utils/plugins/struct-to-component.ts | 2 +- .../builder-lambda-translators/factory.ts | 87 +++++++-- .../ui-plugins/component-transformer.ts | 87 +++++++-- .../ui-plugins/entry-translators/factory.ts | 177 +++++++++++++++++- .../ui-plugins/entry-translators/utils.ts | 24 ++- arkui-plugins/ui-plugins/index.ts | 2 +- 9 files changed, 338 insertions(+), 51 deletions(-) diff --git a/arkui-plugins/common/plugin-context.ts b/arkui-plugins/common/plugin-context.ts index 95843cb7b..3b7a84696 100644 --- a/arkui-plugins/common/plugin-context.ts +++ b/arkui-plugins/common/plugin-context.ts @@ -91,6 +91,9 @@ export interface ProjectConfig { moduleName: string; cachePath: string; dependentModuleList: DependentModuleConfig[]; + projectPath: string, + projectRootPath: string, + integratedHsp: boolean } export type PluginHandlerFunction = () => void; diff --git a/arkui-plugins/common/predefines.ts b/arkui-plugins/common/predefines.ts index 044a48b95..1c49183b7 100644 --- a/arkui-plugins/common/predefines.ts +++ b/arkui-plugins/common/predefines.ts @@ -167,6 +167,9 @@ export const INTERMEDIATE_IMPORT_SOURCE: Map = new Map { - this.taskProcessor = new TaskProcessor(this.hashId, this.configBuilder.buildConfig); + this.taskProcessor = new TaskProcessor(this.hashId, this.configBuilder.buildConfig, tracing); return this.taskProcessor.invokeWorkers(plugins, stopAfter); } @@ -196,7 +196,7 @@ class PluginTester { that.clear(); }); - that.resolve = that.compile(plugins, options.stopAfter); + that.resolve = that.compile(plugins, options.stopAfter, options.tracing); that.compileTests(testName, pluginHooks); }); } diff --git a/arkui-plugins/test/utils/plugins/struct-to-component.ts b/arkui-plugins/test/utils/plugins/struct-to-component.ts index 79c4d6c2e..c993b2294 100644 --- a/arkui-plugins/test/utils/plugins/struct-to-component.ts +++ b/arkui-plugins/test/utils/plugins/struct-to-component.ts @@ -30,7 +30,7 @@ export const structToComponent: Plugins = { if (!!contextPtr) { let program = arkts.getOrUpdateGlobalContext(contextPtr).program; script = program.astNode; - const componentTransformer = new ComponentTransformer(); + const componentTransformer = new ComponentTransformer(this.getProjectConfig(), program.globalAbsName); const programVisitor = new ProgramVisitor({ pluginName: structToComponent.name, state: arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, diff --git a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts index 7171c74dd..24ff6adfd 100644 --- a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts +++ b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts @@ -81,25 +81,43 @@ export class factory { ); } + static createPackageInfoArgForNavigation(): arkts.ETSParameterExpression { + return arkts.factory.createParameterDeclaration( + arkts.factory.createIdentifier( + 'moduleInfo', + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('NavigationModuleInfo')) + ) + ), + undefined + ); + } + /** * update `@ComponentBuilder` decorated method. */ static updateBuilderLambdaMethodDecl( node: arkts.MethodDefinition, - prefixArgs: arkts.ETSParameterExpression[], + styleArg: arkts.ETSParameterExpression, + // prefixArgs: arkts.ETSParameterExpression[], newAnno: arkts.AnnotationUsage[], - newName: string | undefined + newName: string | undefined, + externalSourceName?: string ): arkts.MethodDefinition { const func: arkts.ScriptFunction = node.scriptFunction; - let newParams: arkts.Expression[]; + let newParams: arkts.Expression[] = [styleArg]; if (func.params.length > 0) { - newParams = [...prefixArgs, ...func.params.slice(0, func.params.length - 1)]; + newParams.push(...func.params.slice(0, func.params.length - 1)); if (node.name.name === BuilderLambdaNames.ORIGIN_METHOD_NAME) { newParams.push(this.createReusableKeyArgForCustomComponent()); } + if (externalSourceName === 'arkui.component.xcomponent' && node.name.name === 'XComponent') { + newParams.push(this.createPackageInfoArgForXComponent()); + } + if (externalSourceName === 'arkui.component.navigation' && node.name.name === 'Navigation') { + newParams.push(this.createPackageInfoArgForNavigation()); + } newParams.push(func.params.at(func.params.length - 1)!); - } else { - newParams = prefixArgs; } const updateFunc = arkts.factory .updateScriptFunction( @@ -420,7 +438,9 @@ export class factory { ); reuseId = isReusable ? arkts.factory.createStringLiteral(type.name) : undefined; } - const args: (arkts.AstNode | undefined)[] = [this.createStyleArgInBuilderLambda(lambdaBody, returnType, moduleName)]; + const args: (arkts.AstNode | undefined)[] = [ + this.createStyleArgInBuilderLambda(lambdaBody, returnType, moduleName), + ]; let index = 0; while (index < params.length) { if (isReusable && index === params.length - 1) { @@ -447,7 +467,38 @@ export class factory { packageInfoNode ) ); - } else { + } + else if (type?.name === 'Navigation' && index === params.length - 1) { + ImportCollector.getInstance().collectImport('NavigationModuleInfo'); + const test = arkts.factory.createTSAsExpression( + arkts.factory.createObjectExpression( + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_EXPRESSION, + [ + arkts.factory.createProperty( + arkts.factory.createIdentifier('moduleName'), + arkts.factory.createStringLiteral(projectConfig?.moduleName ?? '') + ), + arkts.factory.createProperty( + arkts.factory.createIdentifier('pagePath'), + arkts.factory.createStringLiteral('') // todo: replace w/ + ), + arkts.factory.createProperty( + arkts.factory.createIdentifier('isUserCreateStack'), + arkts.factory.createBooleanLiteral(true) // todo: check if always true? + ) + ], + false + ), + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('NavigationModuleInfo')) + ), + false + + ); + args.push(this.createOrUpdateArgInBuilderLambda(undefined, undefined, undefined, test)); + args.push(this.createOrUpdateArgInBuilderLambda(leaf.arguments.at(index), projectConfig, type?.name)); + } + else { args.push(this.createOrUpdateArgInBuilderLambda(leaf.arguments.at(index), projectConfig, type?.name)); } index++; @@ -539,20 +590,26 @@ export class factory { const func: arkts.ScriptFunction = node.scriptFunction; const isFunctionCall: boolean = isBuilderLambdaFunctionCall(node); const typeNode: arkts.TypeNode | undefined = builderLambdaMethodDeclType(node); - const prefixArgs: arkts.ETSParameterExpression[] = []; - prefixArgs.push(this.createStyleArgInBuilderLambdaDecl(typeNode, isFunctionCall)); - if (externalSourceName === 'arkui.component.xcomponent' && node.name.name === 'XComponent') { - prefixArgs.push(this.createPackageInfoArgForXComponent()); - } + // const prefixArgs: arkts.ETSParameterExpression[] = []; + // prefixArgs.push(this.createStyleArgInBuilderLambdaDecl(typeNode, isFunctionCall)); + // if (externalSourceName === 'arkui.component.xcomponent' && node.name.name === 'XComponent') { + // prefixArgs.push(this.createPackageInfoArgForXComponent()); + // } + // if (externalSourceName === 'arkui.component.navigation' && node.name.name === 'Navigation') { + // console.log('fyx Navigation', node.dumpSrc()) + // // prefixArgs.push(this.createPackageInfoArgForNavigation()); + // } const newOverloads: arkts.MethodDefinition[] = node.overloads.map((method) => factory.transformBuilderLambdaMethodDecl(method) ); return this.updateBuilderLambdaMethodDecl( node, - prefixArgs, + // prefixArgs, + this.createStyleArgInBuilderLambdaDecl(typeNode, isFunctionCall), removeAnnotationByName(func.annotations, BuilderLambdaNames.ANNOTATION_NAME), - replaceBuilderLambdaDeclMethodName(node.name.name) + replaceBuilderLambdaDeclMethodName(node.name.name), + externalSourceName ).setOverloads(newOverloads); } diff --git a/arkui-plugins/ui-plugins/component-transformer.ts b/arkui-plugins/ui-plugins/component-transformer.ts index 40336dec4..233f1cad6 100644 --- a/arkui-plugins/ui-plugins/component-transformer.ts +++ b/arkui-plugins/ui-plugins/component-transformer.ts @@ -34,7 +34,8 @@ import { collect, createAndInsertImportDeclaration, } from '../common/arkts-utils'; -import { EntryWrapperNames, findEntryWithStorageInClassAnnotations } from './entry-translators/utils'; +import { ProjectConfig } from '../common/plugin-context'; +import { EntryWrapperNames, findEntryParam } from './entry-translators/utils'; import { factory as entryFactory } from './entry-translators/factory'; import { hasDecoratorName, findDecoratorInfos, isDecoratorAnnotation } from './property-translators/utils'; import { factory } from './ui-factory'; @@ -74,10 +75,19 @@ export class ComponentTransformer extends AbstractVisitor { private hasLegacy: boolean = false; private legacyStructMap: Map = new Map(); private legacyCallMap: Map = new Map(); + private projectConfig: ProjectConfig | undefined; + private fileAbsName: string | undefined; + private entryRouteName: string | undefined; - constructor(options?: ComponentTransformerOptions) { + constructor( + projectConfig: ProjectConfig | undefined, + fileAbsName: string | undefined, + options?: ComponentTransformerOptions + ) { const _options: ComponentTransformerOptions = options ?? {}; super(_options); + this.projectConfig = projectConfig; + this.fileAbsName = fileAbsName; } reset(): void { @@ -143,8 +153,48 @@ export class ComponentTransformer extends AbstractVisitor { } processEtsScript(node: arkts.EtsScript): arkts.EtsScript { - if (this.isExternal && this.componentInterfaceCollection.length === 0 && this.entryNames.length === 0) { - return node; + if (this.isExternal) { + if (this.externalSourceName === 'arkui.component.navigation') { + const NavigationModuleInfo = arkts.factory.createInterfaceDeclaration( + [], + arkts.factory.createIdentifier('NavigationModuleInfo'), + undefined, + arkts.factory.createInterfaceBody([ + arkts.factory.createClassProperty( + arkts.factory.createIdentifier('moduleName'), + undefined, + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('string')) + ), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ), + arkts.factory.createClassProperty( + arkts.factory.createIdentifier('pagePath'), + undefined, + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('string')) + ), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ), + arkts.factory.createClassProperty( + arkts.factory.createIdentifier('isUserCreateStack'), + undefined, + arkts.factory.createPrimitiveType(arkts.Es2pandaPrimitiveType.PRIMITIVE_TYPE_BOOLEAN), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ), + ]), + false, + false + ); + NavigationModuleInfo.modifiers = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_EXPORT; + return arkts.factory.updateEtsScript(node, [...node.statements, NavigationModuleInfo]); + } + if (this.componentInterfaceCollection.length === 0 && this.entryNames.length === 0) { + return node; + } } const updateStatements: arkts.AstNode[] = []; if (this.shouldAddLinkIntrinsic) { @@ -160,7 +210,17 @@ export class ComponentTransformer extends AbstractVisitor { if (!this.isEntryPointImported) entryFactory.createAndInsertEntryPointImport(this.program); // normally, we should only have at most one @Entry component in a single file. // probably need to handle error message here. - updateStatements.push(...this.entryNames.map(entryFactory.generateEntryWrapper)); + updateStatements.push( + ...this.entryNames.map((name) => + entryFactory.generateEntryWrapper(name, this.entryRouteName !== undefined) + ) + ); + if (this.entryRouteName !== undefined) { + updateStatements.push(entryFactory.genNavInterface()); + updateStatements.push( + entryFactory.callRegisterNamedRouter(this.entryRouteName, this.projectConfig, this.fileAbsName) + ); + } } if (updateStatements.length > 0) { return arkts.factory.updateEtsScript(node, [...node.statements, ...updateStatements]); @@ -228,10 +288,15 @@ export class ComponentTransformer extends AbstractVisitor { const newDefinitionBody: arkts.AstNode[] = []; if (!!scopeInfo.annotations?.entry) { this.entryNames.push(className); - const entryWithStorage: arkts.ClassProperty | undefined = - findEntryWithStorageInClassAnnotations(definition); - if (!!entryWithStorage) { - newDefinitionBody.push(entryFactory.createEntryLocalStorageInClass(entryWithStorage)); + // const entryWithStorage: arkts.ClassProperty | undefined = + // findEntryWithStorageInClassAnnotations(definition); + // if (!!entryWithStorage) { + // newDefinitionBody.push(entryFactory.createEntryLocalStorageInClass(entryWithStorage)); + // } + // entryFactory.transformEntryParams(definition); + const routeName = findEntryParam(definition, EntryWrapperNames.ROUTE_NAME); + if (routeName && routeName.value && arkts.isStringLiteral(routeName.value)) { + this.entryRouteName = routeName.value.str; } } const newDefinition: arkts.ClassDefinition = this.createNewDefinition( @@ -404,9 +469,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 && args[0] instanceof arkts.ObjectExpression ? args[0] : undefined, }; return generateInstantiateInterop(context); } diff --git a/arkui-plugins/ui-plugins/entry-translators/factory.ts b/arkui-plugins/ui-plugins/entry-translators/factory.ts index 09d1c85b7..f40e45f17 100644 --- a/arkui-plugins/ui-plugins/entry-translators/factory.ts +++ b/arkui-plugins/ui-plugins/entry-translators/factory.ts @@ -14,9 +14,11 @@ */ import * as arkts from '@koalaui/libarkts'; +import * as path from 'path'; import { EntryWrapperNames } from './utils'; import { annotation, createAndInsertImportDeclaration } from '../../common/arkts-utils'; import { ENTRY_POINT_IMPORT_SOURCE_NAME } from '../../common/predefines'; +import { ProjectConfig } from '../../common/plugin-context'; export class factory { /** @@ -141,11 +143,7 @@ export class factory { */ static generateEntryProperty(name: string): arkts.ClassProperty { const exp = arkts.factory.createExpressionStatement( - arkts.factory.createCallExpression( - arkts.factory.createIdentifier(name), - undefined, - [] - ) + arkts.factory.createCallExpression(arkts.factory.createIdentifier(name), undefined, []) ); const key: arkts.Identifier = arkts.factory.createIdentifier(EntryWrapperNames.ENTRY_FUNC); const block: arkts.BlockStatement = arkts.factory.createBlock([exp]); @@ -181,7 +179,7 @@ export class factory { * * @param name class/struct name that has `@Entry` annotation. */ - static generateEntryWrapper(name: string): arkts.ClassDeclaration { + static generateEntryWrapper(name: string, namedRouter: boolean): arkts.ClassDeclaration { const ctor = factory.generateConstructor(); const definition: arkts.ClassDefinition = arkts.factory .createClassDefinition( @@ -195,7 +193,11 @@ export class factory { arkts.factory.createIdentifier(EntryWrapperNames.ENTRY_POINT_CLASS_NAME) ) ), - [factory.generateEntryFunction(name), ctor], + [ + ...(namedRouter ? [factory.genRegisterNamedRouter()] : []), + factory.generateEntryFunction(name), + ctor, + ], arkts.Es2pandaClassDefinitionModifiers.CLASS_DEFINITION_MODIFIERS_CLASS_DECL | arkts.Es2pandaClassDefinitionModifiers.CLASS_DEFINITION_MODIFIERS_DECLARATION | arkts.Es2pandaClassDefinitionModifiers.CLASS_DEFINITION_MODIFIERS_ID_REQUIRED, @@ -281,4 +283,165 @@ export class factory { program ); } + + /** + * generate interface NavInterface when entry contains routeName + */ + static genNavInterface(): arkts.TSInterfaceDeclaration { + return arkts.factory.createInterfaceDeclaration( + [], + arkts.factory.createIdentifier('NavInterface'), + undefined, + arkts.factory.createInterfaceBody([ + this.genClassProp('bundleName'), + this.genClassProp('moduleName'), + this.genClassProp('pagePath'), + this.genClassProp('pageFullPath'), + this.genClassProp('integratedHsp'), //todo: check type + ]), + false, + false + ); + } + + /** + * helper for genNavInterface to generate class properties + */ + static genClassProp(propName: string): arkts.ClassProperty { + return arkts.factory.createClassProperty( + arkts.factory.createIdentifier(propName), + undefined, + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('string')) + ), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PUBLIC, + false + ); + } + + /** + * generate genRegisterNamedRouter method in __EntryWrapper + */ + static genRegisterNamedRouter(): arkts.MethodDefinition { + return arkts.factory.createMethodDefinition( + arkts.Es2pandaMethodDefinitionKind.METHOD_DEFINITION_KIND_METHOD, + arkts.factory.createIdentifier('RegisterNamedRouter'), + arkts.factory.createScriptFunction( + arkts.factory.createBlock([]), + arkts.factory.createFunctionSignature( + undefined, + [ + arkts.factory.createParameterDeclaration( + arkts.factory.createIdentifier( + 'routerName', + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('string')) + ) + ), + undefined + ), + arkts.factory.createParameterDeclaration( + arkts.factory.createIdentifier( + 'instance', + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart( + arkts.factory.createIdentifier('__EntryWrapper') + ) + ) + ), + undefined + ), + arkts.factory.createParameterDeclaration( + arkts.factory.createIdentifier( + 'param', + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart( + arkts.factory.createIdentifier('NavInterface') + ) + ) + ), + undefined + ), + ], + undefined, + false + ), + arkts.Es2pandaScriptFunctionFlags.SCRIPT_FUNCTION_FLAGS_METHOD, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC + ), + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_STATIC, + false + ); + } + + /** + * generate __EntryWrapper.RegisterNamedRouter(...) when entry contains routeName + */ + static callRegisterNamedRouter( + entryRouteName: string, + projectConfig: ProjectConfig | undefined, + fileAbsName: string | undefined + ): arkts.ExpressionStatement { + const pagePath = path + .relative(projectConfig?.projectPath ?? '', fileAbsName ?? '') + .replace(/\\/g, '/') + .replace(/\.ets$/, ''); + const pageFullPath = path + .relative(projectConfig?.projectRootPath ?? '', fileAbsName ?? '') + .replace(/\\/g, '/') + .replace(/\.ets$/, ''); + return arkts.factory.createExpressionStatement( + arkts.factory.createCallExpression( + arkts.factory.createMemberExpression( + arkts.factory.createIdentifier('__EntryWrapper'), + arkts.factory.createIdentifier('RegisterNamedRouter'), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ), + undefined, + [ + arkts.factory.createStringLiteral(entryRouteName), + arkts.factory.createETSNewClassInstanceExpression( + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('__EntryWrapper')) + ), + [] + ), + arkts.factory.createTSAsExpression( + arkts.factory.createObjectExpression( + arkts.Es2pandaAstNodeType.AST_NODE_TYPE_OBJECT_EXPRESSION, + [ + arkts.factory.createProperty( + arkts.factory.createIdentifier('bundleName'), + arkts.factory.createStringLiteral(projectConfig?.bundleName ?? '') + ), + arkts.factory.createProperty( + arkts.factory.createIdentifier('moduleName'), + arkts.factory.createStringLiteral(projectConfig?.moduleName ?? '') + ), + arkts.factory.createProperty( + arkts.factory.createIdentifier('pagePath'), + arkts.factory.createStringLiteral(pagePath) + ), + arkts.factory.createProperty( + arkts.factory.createIdentifier('pageFullPath'), + arkts.factory.createStringLiteral(pageFullPath) + ), + arkts.factory.createProperty( + arkts.factory.createIdentifier('integratedHsp'), + arkts.factory.createStringLiteral(projectConfig?.integratedHsp?.toString() ?? '') + ), + ], + false + ), + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('NavInterface')) + ), + false + ), + ] + ) + ); + } } diff --git a/arkui-plugins/ui-plugins/entry-translators/utils.ts b/arkui-plugins/ui-plugins/entry-translators/utils.ts index a987f631b..832a11e92 100644 --- a/arkui-plugins/ui-plugins/entry-translators/utils.ts +++ b/arkui-plugins/ui-plugins/entry-translators/utils.ts @@ -24,6 +24,7 @@ export enum EntryWrapperNames { ENTRY_STORAGE_ANNOTATION_KEY = 'storage', ENTRY_STORAGE_LOCAL_STORAGE_PROPERTY_NAME = '_entry_local_storage_', ENTRY_POINT_CLASS_NAME = 'EntryPoint', + ROUTE_NAME = 'routeName' } /** @@ -52,7 +53,7 @@ export class EntryHandler { public createEntryWrapper(): arkts.ClassDeclaration[] { let result: arkts.ClassDeclaration[] = []; this.entryDefClassName.forEach((classname) => { - result.push(factory.generateEntryWrapper(classname)); + result.push(factory.generateEntryWrapper(classname, false)); }); return result; } @@ -66,18 +67,15 @@ export function isEntryWrapperClass(node: arkts.AstNode): node is arkts.ClassDec } /** - * find `{storage: ""}` in `@Entry({storage: ""})` (i.e. annotation's properties). + * find annotation's specified property in `@Entry()` (i.e. storage, useSharedStorage, etc.). * * @param node class definition node */ -export function findEntryWithStorageInClassAnnotations(node: arkts.ClassDefinition): arkts.ClassProperty | undefined { - const annotation = node.annotations.find((anno) => { - if (!isAnnotation(anno, StructDecoratorNames.ENTRY)) return false; - const property = anno.properties?.at(0); - if (!property || !arkts.isClassProperty(property)) return false; - if (!property.key || !arkts.isIdentifier(property.key)) return false; - if (!property.value || !arkts.isStringLiteral(property.value)) return false; - return property.key.name === EntryWrapperNames.ENTRY_STORAGE_ANNOTATION_KEY; - }); - return annotation?.properties?.at(0) as arkts.ClassProperty | undefined; -} +export function findEntryParam(node: arkts.ClassDefinition, paramName: EntryWrapperNames): arkts.ClassProperty | undefined { + const annotation = node.annotations.find((anno) => isAnnotation(anno, StructDecoratorNames.ENTRY)) + if(!annotation || !annotation.properties){ + return undefined; + } + const property = annotation.properties.find((property)=> arkts.isClassProperty(property) && property.key && arkts.isIdentifier(property.key) && property.key.name === paramName) + return property as arkts.ClassProperty | undefined; +} diff --git a/arkui-plugins/ui-plugins/index.ts b/arkui-plugins/ui-plugins/index.ts index a50014ecf..f56ae0251 100644 --- a/arkui-plugins/ui-plugins/index.ts +++ b/arkui-plugins/ui-plugins/index.ts @@ -50,7 +50,7 @@ function parsedTransform(this: PluginContext): arkts.EtsScript | undefined { program.fileNameWithExtension ); arkts.Performance.getInstance().createEvent('ui-parsed'); - const componentTransformer = new ComponentTransformer(); + const componentTransformer = new ComponentTransformer(this.getProjectConfig(), program.globalAbsName); const preprocessorTransformer = new PreprocessorTransformer(); const programVisitor = new ProgramVisitor({ pluginName: uiTransform.name, -- Gitee