From 8dfc966d2c2676c9d79a0e71bd3af8b347c7b044 Mon Sep 17 00:00:00 2001 From: Yuxin Feng Date: Fri, 20 Jun 2025 16:47:46 +0800 Subject: [PATCH] revert uiplugin xcomponent transform Signed-off-by: Yuxin Feng Change-Id: I22f7719aff595aedcdb55014452a06ee795bfc62 --- .../demo/mock/xcomponent/xcomponent-basic.ets | 19 -- .../xcomponent/xcomponent-basic.test.ts | 263 ------------------ .../builder-lambda-translators/factory.ts | 33 --- 3 files changed, 315 deletions(-) delete mode 100644 arkui-plugins/test/demo/mock/xcomponent/xcomponent-basic.ets delete mode 100644 arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts diff --git a/arkui-plugins/test/demo/mock/xcomponent/xcomponent-basic.ets b/arkui-plugins/test/demo/mock/xcomponent/xcomponent-basic.ets deleted file mode 100644 index aa644d5ed..000000000 --- a/arkui-plugins/test/demo/mock/xcomponent/xcomponent-basic.ets +++ /dev/null @@ -1,19 +0,0 @@ -import {Component, Flex, XComponent, FlexDirection, XComponentType, Entry, XComponentController, ItemAlign, FlexAlign, XComponentParameter} from '@ohos.arkui.component' - -@Entry -@Component -struct Index { - myXComponentController: XComponentController = new XComponentController(); - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { - XComponent({ - id: 'xComponentId', - type: XComponentType.TEXTURE, - libraryname: 'nativerender', - controller: this.myXComponentController - } as XComponentParameter) - } - .width('100%') - .height('100%') - } -} \ No newline at end of file diff --git a/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts deleted file mode 100644 index f3b40bcec..000000000 --- a/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as path from 'path'; -import { PluginTester } from '../../../utils/plugin-tester'; -import { mockBuildConfig } from '../../../utils/artkts-config'; -import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../utils/path-config'; -import { parseDumpSrc } from '../../../utils/parse-string'; -import { recheck, uiNoRecheck } from '../../../utils/plugins'; -import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; -import { uiTransform } from '../../../../ui-plugins'; -import { Plugins } from '../../../../common/plugin-context'; - -const XCOMPONENT_DIR_PATH: string = 'xcomponent'; - -const buildConfig: BuildConfig = mockBuildConfig(); -buildConfig.compileFiles = [ - path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, XCOMPONENT_DIR_PATH, 'xcomponent-basic.ets'), -]; - -const xcomponentTransform: Plugins = { - name: 'xcomponent', - parsed: uiTransform().parsed, -}; - -const pluginTester = new PluginTester('test basic XComponent transform', buildConfig); - -const expectedScript: string = ` - -import { memo as memo } from "arkui.stateManagement.runtime"; - -import { FlexAttribute as FlexAttribute } from "arkui.component.flex"; - -import { PageLifeCycle as PageLifeCycle } from "arkui.component.customComponent"; - -import { EntryPoint as EntryPoint } from "arkui.UserView"; - -import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - -import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - -import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - -import { Component as Component, Flex as Flex, XComponent as XComponent, FlexDirection as FlexDirection, XComponentType as XComponentType, Entry as Entry, XComponentController as XComponentController, ItemAlign as ItemAlign, FlexAlign as FlexAlign, XComponentParameter as XComponentParameter } from "@ohos.arkui.component"; - -function main() {} - - - -@Entry({shared:false,storage:"",routeName:""}) @Component() final struct Index extends CustomComponent implements PageLifeCycle { - public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_myXComponentController = ((({let gensym___221905990 = initializers; - (((gensym___221905990) == (null)) ? undefined : gensym___221905990.myXComponentController)})) ?? (new XComponentController())); - } - - public __updateStruct(initializers: __Options_Index | undefined): void {} - - private __backing_myXComponentController?: XComponentController; - - public get myXComponentController(): XComponentController { - return (this.__backing_myXComponentController as XComponentController); - } - - public set myXComponentController(value: XComponentController) { - this.__backing_myXComponentController = value; - } - - @memo() public build() { - Flex(((instance: FlexAttribute): void => { - instance.width("100%").height("100%"); - return; - }), { - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Start, - }, (() => { - XComponent(undefined, ({ - id: "xComponentId", - type: XComponentType.TEXTURE, - libraryname: "nativerender", - controller: this.myXComponentController, - } as XComponentParameter), ""); - })); - } - - private constructor() {} - -} - -@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Index { - set myXComponentController(myXComponentController: XComponentController | undefined) - - get myXComponentController(): XComponentController | undefined - -} - -class __EntryWrapper extends EntryPoint { - @memo() public entry(): void { - Index._instantiateImpl(undefined, (() => { - return new Index(); - })); - } - - public constructor() {} - -} -`; - -const expectedHeader: string = ` - -import { memo as memo } from "arkui.stateManagement.runtime"; - -import { ImageAIOptions as ImageAIOptions, ImageAnalyzerConfig as ImageAnalyzerConfig } from "./imageCommon"; - -import { CommonMethod as CommonMethod, AttributeModifier as AttributeModifier } from "./common"; - -import { XComponentType as XComponentType } from "./enums"; - -import { VoidCallback as VoidCallback } from "./units"; - -import { memo as memo, ComponentBuilder as ComponentBuilder } from "./../stateManagement/runtime"; - -function main() {} - - -@memo() export function XComponent(@memo() style?: ((instance: XComponentAttribute)=> void), params: XComponentParameter | XComponentOptions | NativeXComponentParameters, packageInfo: string, @memo() content_?: (()=> void)): void - - -export declare interface SurfaceRect { - set offsetX(offsetX: number | undefined) - - get offsetX(): number | undefined - set offsetY(offsetY: number | undefined) - - get offsetY(): number | undefined - set surfaceWidth(surfaceWidth: number) - - get surfaceWidth(): number - set surfaceHeight(surfaceHeight: number) - - get surfaceHeight(): number - -} - -export declare interface SurfaceRotationOptions { - set lock(lock: boolean | undefined) - - get lock(): boolean | undefined - -} - -export declare class XComponentController { - public constructor() - - public getXComponentSurfaceId(): string - - public getXComponentContext(): Object - - public setXComponentSurfaceRect(rect: SurfaceRect): void - - public getXComponentSurfaceRect(): SurfaceRect - - public setXComponentSurfaceRotation(rotationOptions: SurfaceRotationOptions): void - - public getXComponentSurfaceRotation(): Required - - public onSurfaceCreated(surfaceId: string): void - - public onSurfaceChanged(surfaceId: string, rect: SurfaceRect): void - - public onSurfaceDestroyed(surfaceId: string): void - - public startImageAnalyzer(config: ImageAnalyzerConfig): Promise - - public stopImageAnalyzer(): void - -} - -export declare interface XComponentOptions { - set type(type: XComponentType) - - get type(): XComponentType - set controller(controller: XComponentController) - - get controller(): XComponentController - set imageAIOptions(imageAIOptions: ImageAIOptions | undefined) - - get imageAIOptions(): ImageAIOptions | undefined - set screenId(screenId: number | undefined) - - get screenId(): number | undefined - -} - -export declare interface NativeXComponentParameters { - set type(type: XComponentType) - - get type(): XComponentType - set imageAIOptions(imageAIOptions: ImageAIOptions | undefined) - - get imageAIOptions(): ImageAIOptions | undefined - -} - -export type OnNativeLoadCallback = ((event?: object)=> void); - -export declare interface XComponentAttribute extends CommonMethod { - onLoad(callback: OnNativeLoadCallback | undefined): this - onDestroy(event: VoidCallback | undefined): this - enableAnalyzer(enable: boolean | undefined): this - enableSecure(isSecure: boolean | undefined): this - hdrBrightness(brightness: number | undefined): this - enableTransparentLayer(enabled: boolean | undefined): this - attributeModifier(modifier: AttributeModifier | AttributeModifier | undefined): this - -} - -export declare interface XComponentParameter { - set id(id: string) - - get id(): string - set type(type: XComponentType) - - get type(): XComponentType - set libraryname(libraryname: string | undefined) - - get libraryname(): string | undefined - set controller(controller: XComponentController | undefined) - - get controller(): XComponentController | undefined - -} -` - -function testXComponentTransformer(this: PluginTestContext): void { - expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); - expect(parseDumpSrc(this.declContexts?.['arkui.component.xcomponent']?.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedHeader)); - -} - -pluginTester.run( - 'test basic XComponent transform', - [xcomponentTransform, uiNoRecheck, recheck], - { - 'checked:ui-no-recheck': [testXComponentTransformer], - }, - { - stopAfter: 'checked', - tracing: {externalSourceNames:['arkui.component.xcomponent']} - } -); diff --git a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts index 8d3d688f1..69c9f1e86 100644 --- a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts +++ b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts @@ -50,22 +50,6 @@ import { AnimationNames, BindableDecl, DecoratorIntrinsicNames, StructDecoratorN import { ImportCollector } from '../../common/import-collector'; export class factory { - - /** - * generate `packageInfo: string` in `@ComponentBuilder` XComponent - */ - static createPackageInfoArgForXComponent(): arkts.ETSParameterExpression { - return arkts.factory.createParameterDeclaration( - arkts.factory.createIdentifier( - 'packageInfo', - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier('string')) - ) - ), - undefined - ); - } - /** * update `@ComponentBuilder` decorated method. */ @@ -80,9 +64,6 @@ export class factory { let newParams: arkts.Expression[] = [styleArg]; if (func.params.length > 0) { newParams.push(...this.updateBuilderParameters(func.params).slice(0, func.params.length - 1)); - if (externalSourceName === 'arkui.component.xcomponent' && node.name.name === 'XComponent') { - newParams.push(this.createPackageInfoArgForXComponent()); - } newParams.push(func.params.at(func.params.length - 1)!); } const updateFunc = arkts.factory @@ -431,20 +412,6 @@ export class factory { arkts.factory.createUndefinedLiteral() ) ); - } else if (type?.name === 'XComponent' && index === params.length - 1) { - let packageInfo: string = ''; - if (projectConfig?.bundleName && projectConfig?.moduleName) { - packageInfo = projectConfig?.bundleName + '/' + projectConfig?.moduleName; - } - const packageInfoNode = arkts.factory.createStringLiteral(packageInfo); - args.push( - this.createOrUpdateArgInBuilderLambda( - leaf.arguments.at(index), - projectConfig, - type?.name, - packageInfoNode - ) - ); } else { args.push(this.createOrUpdateArgInBuilderLambda(leaf.arguments.at(index), projectConfig, type?.name)); } -- Gitee