diff --git a/arkui-plugins/test/demo/mock/customdialog/customdialog-property.ets b/arkui-plugins/test/demo/mock/customdialog/customdialog-property.ets new file mode 100644 index 0000000000000000000000000000000000000000..a56ccce2ecd2c3c25abfac186b67798d519a5dcc --- /dev/null +++ b/arkui-plugins/test/demo/mock/customdialog/customdialog-property.ets @@ -0,0 +1,50 @@ +/* + * 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 { Text, Column, Component, Entry, Button, ClickEvent, CustomDialog, CustomDialogController, CustomDialogControllerOptions } from "@ohos.arkui.component" +import hilog from '@ohos.hilog' + + + +@CustomDialog +struct CustomDialogExample { + test: number = 2; + controller?: CustomDialogController; + + build() { + Column() { + Text('我是内容').fontSize(20) + Button('点我关闭弹窗') + .onClick((e:ClickEvent) => { + if(this.controller) { + this.controller?.close(); + } + }) + } + } +} + +@Entry +@Component +struct MyStateSample { + dialogController: CustomDialogController | undefined = new CustomDialogController({ + builder: CustomDialogExample({test: 1}) + }) + build() { + Column() { + } + } +} + diff --git a/arkui-plugins/test/demo/mock/customdialog/customdialog-variable.ets b/arkui-plugins/test/demo/mock/customdialog/customdialog-variable.ets new file mode 100644 index 0000000000000000000000000000000000000000..487bf5de8db78b562e036bd587d2cb2317c08e7b --- /dev/null +++ b/arkui-plugins/test/demo/mock/customdialog/customdialog-variable.ets @@ -0,0 +1,50 @@ +/* + * 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 { Text, Column, Component, Entry, Button, ClickEvent, CustomDialog, CustomDialogController, CustomDialogControllerOptions } from "@ohos.arkui.component" +import { State, Link, Prop } from "@ohos.arkui.stateManagement" +import hilog from '@ohos.hilog' + +@CustomDialog +struct CustomDialogExample { + test?: number = 2; + str: string = 'test'; + controller?: CustomDialogController; + + build() { + Column() { + Text('我是内容').fontSize(20) + Button('点我关闭弹窗') + .onClick((e:ClickEvent) => { + if(this.controller != undefined && this.controller != null) { + this.controller?.close(); + } + }) + } + } +} + + +@Component +struct MyStateSample { + build() { + Button('test') + .onClick((e:ClickEvent) => { + let dialogController: CustomDialogController | undefined = new CustomDialogController({ + builder: CustomDialogExample({test: 1, str: 'hello'}) + }) + }) + } +} \ No newline at end of file diff --git a/arkui-plugins/test/ut/ui-plugins/customdialog/customdialog-property.test.ts b/arkui-plugins/test/ut/ui-plugins/customdialog/customdialog-property.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..69ec983e14f233429671b6d2ebae816d1211cdef --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/customdialog/customdialog-property.test.ts @@ -0,0 +1,416 @@ +/* + * 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 { memoNoRecheck, recheck, uiNoRecheck } from '../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; +import { Plugins } from '../../../../common/plugin-context'; +import { uiTransform } from '../../../../ui-plugins'; + +const CUSTOMDIALOG_DIR_PATH: string = 'customdialog'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, CUSTOMDIALOG_DIR_PATH, 'customdialog-property.ets'), +]; + +const pluginTester = new PluginTester('test customdialogcontroller as property', buildConfig); + +const parsedTransform: Plugins = { + name: 'customdialog', + parsed: uiTransform().parsed +}; + +function testCustomDialogTransformer(this: PluginTestContext): void { + const expectedScript: string = ` +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + +import { NavInterface as NavInterface } from "arkui.UserView"; + +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 { Text as Text, Column as Column, Component as Component, Entry as Entry, Button as Button, ClickEvent as ClickEvent, CustomDialog as CustomDialog, CustomDialogController as CustomDialogController, CustomDialogControllerOptions as CustomDialogControllerOptions } from "@ohos.arkui.component"; + +import hilog from "@ohos.hilog"; + +function main() {} + +__EntryWrapper.RegisterNamedRouter("", new __EntryWrapper(), ({ + bundleName: "com.example.myapplication", + moduleName: "entry", + pagePath: "pages/new", + pageFullPath: "demo/localtest/entry/src/main/ets/pages/new", + integratedHsp: "false", +} as NavInterface)); + +@CustomDialog() final struct CustomDialogExample extends CustomComponentV2 { + public __initializeStruct(initializers: __Options_CustomDialogExample | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_test = ((({let gensym___68443901 = initializers; + (((gensym___68443901) == (null)) ? undefined : gensym___68443901.test)})) ?? (2)); + this.__backing_controller = ((({let gensym___93787132 = initializers; + (((gensym___93787132) == (null)) ? undefined : gensym___93787132.controller)})) ?? (undefined)); + } + + public __updateStruct(initializers: __Options_CustomDialogExample | undefined): void {} + + private __backing_test?: number; + + public get test(): number { + return (this.__backing_test as number); + } + + public set test(value: number) { + this.__backing_test = value; + } + + private __backing_controller?: CustomDialogController | undefined; + + public get controller(): CustomDialogController | undefined { + return (this.__backing_controller as CustomDialogController | undefined); + } + + public set controller(value: CustomDialogController | undefined) { + this.__backing_controller = value; + } + + public __setDialogController__(controller: CustomDialogController): void { + this.controller = controller; + } + + @memo() public build() { + Column(undefined, (() => { + Text(((instance: TextAttribute): void => { + instance.fontSize(20); + return; + }), "我是内容"); + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => { + if (this.controller) { + ({let gensym%%_67 = this.controller; + (((gensym%%_67) == (null)) ? undefined : gensym%%_67.close())}); + } + })); + return; + }), "点我关闭弹窗"); + })); + } + + private constructor() {} + +} + +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { + public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_dialogController = ((({let gensym___145518823 = initializers; + (((gensym___145518823) == (null)) ? undefined : gensym___145518823.dialogController)})) ?? (new CustomDialogController(({ + builder: (() => { + CustomDialogExample._instantiateImpl(undefined, ((): CustomDialogExample => { + let newInstance = new CustomDialogExample(); + newInstance.__setDialogController__((this.dialogController as CustomDialogController)); + return newInstance; + }), ({ + test: 1, + } as __Options_CustomDialogExample)); + }), + } as CustomDialogControllerOptions), this))); + } + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} + + private __backing_dialogController?: CustomDialogController | undefined; + + public get dialogController(): CustomDialogController | undefined { + return (this.__backing_dialogController as CustomDialogController | undefined); + } + + public set dialogController(value: CustomDialogController | undefined) { + this.__backing_dialogController = value; + } + + @memo() public build() { + Column(undefined, (() => {})); + } + + private constructor() {} + +} + +@CustomDialog() export interface __Options_CustomDialogExample { + set test(test: number | undefined) + + get test(): number | undefined + set controller(controller: CustomDialogController | undefined | undefined) + + get controller(): CustomDialogController | undefined | undefined + +} + +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { + set dialogController(dialogController: CustomDialogController | undefined | undefined) + + get dialogController(): CustomDialogController | undefined | undefined + +} + +class __EntryWrapper extends EntryPoint { + @memo() public entry(): void { + MyStateSample._instantiateImpl(undefined, (() => { + return new MyStateSample(); + })); + } + + public constructor() {} + +} + +`; + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +function testMemoTransformer(this: PluginTestContext): void { + const expectedScript: string = ` + +import { __memo_context_type as __memo_context_type, __memo_id_type as __memo_id_type } from "arkui.stateManagement.runtime"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + +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 { Text as Text, Column as Column, Component as Component, Entry as Entry, Button as Button, ClickEvent as ClickEvent, CustomDialog as CustomDialog, CustomDialogController as CustomDialogController, CustomDialogControllerOptions as CustomDialogControllerOptions } from "@ohos.arkui.component"; + +import hilog from "@ohos.hilog"; + +function main() {} + + + +@CustomDialog() final struct CustomDialogExample extends CustomComponentV2 { + public __initializeStruct(initializers: __Options_CustomDialogExample | undefined, @memo() content: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined): void { + this.__backing_test = ((({let gensym___68443901 = initializers; + (((gensym___68443901) == (null)) ? undefined : gensym___68443901.test)})) ?? (2)); + this.__backing_controller = ((({let gensym___93787132 = initializers; + (((gensym___93787132) == (null)) ? undefined : gensym___93787132.controller)})) ?? (undefined)); + } + + public __updateStruct(initializers: __Options_CustomDialogExample | undefined): void {} + + private __backing_test?: number; + + set test(value: number) { + this.__backing_test = value; + } + + public get test(): number { + return (this.__backing_test as number); + } + + private __backing_controller?: CustomDialogController | undefined; + + set controller(value: CustomDialogController | undefined) { + this.__backing_controller = value; + } + + public get controller(): CustomDialogController | undefined { + return (this.__backing_controller as CustomDialogController | undefined); + } + + public __setDialogController__(controller: CustomDialogController): void { + this.controller = controller; + } + + public build(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (223048307)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + Column(__memo_context, ((__memo_id) + (111339450)), undefined, (() => { + Text(__memo_context, ((__memo_id) + (112301077)), ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, instance: TextAttribute): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (57298302)), 1); + const __memo_parameter_instance = __memo_scope.param(0, instance); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_instance.value.fontSize(20); + { + __memo_scope.recache(); + return; + } + }), "我是内容"); + Button(__memo_context, ((__memo_id) + (143562775)), ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, instance: ButtonAttribute): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (92536313)), 1); + const __memo_parameter_instance = __memo_scope.param(0, instance); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_instance.value.onClick(((e: ClickEvent) => { + if (this.controller) { + ({let gensym%%_67 = this.controller; + (((gensym%%_67) == (null)) ? undefined : gensym%%_67.close())}); + } + })); + { + __memo_scope.recache(); + return; + } + }), "点我关闭弹窗"); + })); + { + __memo_scope.recache(); + return; + } + } + + private constructor() {} + +} + +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { + public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined): void { + this.__backing_dialogController = ((({let gensym___145518823 = initializers; + (((gensym___145518823) == (null)) ? undefined : gensym___145518823.dialogController)})) ?? (new CustomDialogController(({ + builder: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (47497983)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + CustomDialogExample._instantiateImpl(__memo_context, ((__memo_id) + (2312069)), undefined, ((): CustomDialogExample => { + let newInstance = new CustomDialogExample(); + newInstance.__setDialogController__((this.dialogController as CustomDialogController)); + return newInstance; + }), ({ + test: 1, + } as __Options_CustomDialogExample)); + { + __memo_scope.recache(); + return; + } + }), + } as CustomDialogControllerOptions), this))); + } + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} + + private __backing_dialogController?: CustomDialogController | undefined; + + set dialogController(value: CustomDialogController | undefined) { + this.__backing_dialogController = value; + } + + public get dialogController(): CustomDialogController | undefined { + return (this.__backing_dialogController as CustomDialogController | undefined); + } + + public build(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (53202779)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + Column(__memo_context, ((__memo_id) + (86237429)), undefined, (() => {})); + { + __memo_scope.recache(); + return; + } + } + + private constructor() {} + +} + +@CustomDialog() export interface __Options_CustomDialogExample { + set test(test: number | undefined) + + get test(): number | undefined + set controller(controller: CustomDialogController | undefined | undefined) + + get controller(): CustomDialogController | undefined | undefined + +} + +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { + set dialogController(dialogController: CustomDialogController | undefined | undefined) + + get dialogController(): CustomDialogController | undefined | undefined + +} + +class __EntryWrapper extends EntryPoint { + public entry(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (198323794)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + MyStateSample._instantiateImpl(__memo_context, ((__memo_id) + (45875559)), undefined, (() => { + return new MyStateSample(); + })); + { + __memo_scope.recache(); + return; + } + } + + public constructor() {} + +} + +`; + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'transform customdialog property', + [parsedTransform, uiNoRecheck, recheck, memoNoRecheck, recheck], + { + 'checked:customdialog-no-recheck': [testCustomDialogTransformer], + 'checked:memo-no-recheck': [testMemoTransformer], + }, + { + stopAfter: 'checked', + } +); diff --git a/arkui-plugins/test/ut/ui-plugins/customdialog/customdialog-variable.test.ts b/arkui-plugins/test/ut/ui-plugins/customdialog/customdialog-variable.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..7de8de33aa05d006bc5457b03c8215d70d3e4361 --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/customdialog/customdialog-variable.test.ts @@ -0,0 +1,393 @@ +/* + * 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 { memoNoRecheck, recheck, uiNoRecheck } from '../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; +import { Plugins } from '../../../../common/plugin-context'; +import { uiTransform } from '../../../../ui-plugins'; + +const CUSTOMDIALOG_DIR_PATH: string = 'customdialog'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, CUSTOMDIALOG_DIR_PATH, 'customdialog-variable.ets'), +]; + +const pluginTester = new PluginTester('test customdialogcontroller as variable', buildConfig); + +const parsedTransform: Plugins = { + name: 'customdialog', + parsed: uiTransform().parsed +}; + +function testCustomDialogTransformer(this: PluginTestContext): void { + const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + +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 { Text as Text, Column as Column, Component as Component, Entry as Entry, Button as Button, ClickEvent as ClickEvent, CustomDialog as CustomDialog, CustomDialogController as CustomDialogController, CustomDialogControllerOptions as CustomDialogControllerOptions } from "@ohos.arkui.component"; + +import hilog from "@ohos.hilog"; + +function main() {} + + + +@CustomDialog() final struct CustomDialogExample extends CustomComponentV2 { + public __initializeStruct(initializers: __Options_CustomDialogExample | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_test = ((({let gensym___68443901 = initializers; + (((gensym___68443901) == (null)) ? undefined : gensym___68443901.test)})) ?? (2)); + this.__backing_str = ((({let gensym___249074315 = initializers; + (((gensym___249074315) == (null)) ? undefined : gensym___249074315.str)})) ?? ("test")); + this.__backing_controller = ((({let gensym___110836778 = initializers; + (((gensym___110836778) == (null)) ? undefined : gensym___110836778.controller)})) ?? (undefined)); + } + + public __updateStruct(initializers: __Options_CustomDialogExample | undefined): void {} + + private __backing_test?: number | undefined; + + public get test(): number | undefined { + return (this.__backing_test as number | undefined); + } + + public set test(value: number | undefined) { + this.__backing_test = value; + } + + private __backing_str?: string; + + public get str(): string { + return (this.__backing_str as string); + } + + public set str(value: string) { + this.__backing_str = value; + } + + private __backing_controller?: CustomDialogController | undefined; + + public get controller(): CustomDialogController | undefined { + return (this.__backing_controller as CustomDialogController | undefined); + } + + public set controller(value: CustomDialogController | undefined) { + this.__backing_controller = value; + } + + public __setDialogController__(controller: CustomDialogController): void { + this.controller = controller; + } + + @memo() public build() { + Column(undefined, (() => { + Text(((instance: TextAttribute): void => { + instance.fontSize(20); + return; + }), "我是内容"); + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => { + if (((((this.controller) != (undefined))) && (((this.controller) != (null))))) { + ({let gensym%%_67 = this.controller; + (((gensym%%_67) == (null)) ? undefined : gensym%%_67.close())}); + } + })); + return; + }), "点我关闭弹窗"); + })); + } + + private constructor() {} + +} + +@Component() final struct MyStateSample extends CustomComponent { + public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} + + @memo() public build() { + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => { + let dialogController: CustomDialogController | undefined = undefined; + dialogController = new CustomDialogController(({ + builder: (() => { + CustomDialogExample._instantiateImpl(undefined, ((): CustomDialogExample => { + let newInstance = new CustomDialogExample(); + const dialogController_Temp = dialogController; + newInstance.__setDialogController__((dialogController_Temp as CustomDialogController)); + return newInstance; + }), ({ + test: 1, + str: "hello", + } as __Options_CustomDialogExample)); + }), + } as CustomDialogControllerOptions), this); + })); + return; + }), "test"); + } + + private constructor() {} + +} + +@CustomDialog() export interface __Options_CustomDialogExample { + set test(test: number | undefined | undefined) + + get test(): number | undefined | undefined + set str(str: string | undefined) + + get str(): string | undefined + set controller(controller: CustomDialogController | undefined | undefined) + + get controller(): CustomDialogController | undefined | undefined + +} + +@Component() export interface __Options_MyStateSample { + +} + +`; + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +function testMemoTransformer(this: PluginTestContext): void { + const expectedScript: string = ` + +import { __memo_context_type as __memo_context_type, __memo_id_type as __memo_id_type } from "arkui.stateManagement.runtime"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + +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 { Text as Text, Column as Column, Component as Component, Entry as Entry, Button as Button, ClickEvent as ClickEvent, CustomDialog as CustomDialog, CustomDialogController as CustomDialogController, CustomDialogControllerOptions as CustomDialogControllerOptions } from "@ohos.arkui.component"; + +import hilog from "@ohos.hilog"; + +function main() {} + + + +@CustomDialog() final struct CustomDialogExample extends CustomComponentV2 { + public __initializeStruct(initializers: __Options_CustomDialogExample | undefined, @memo() content: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined): void { + this.__backing_test = ((({let gensym___68443901 = initializers; + (((gensym___68443901) == (null)) ? undefined : gensym___68443901.test)})) ?? (2)); + this.__backing_str = ((({let gensym___249074315 = initializers; + (((gensym___249074315) == (null)) ? undefined : gensym___249074315.str)})) ?? ("test")); + this.__backing_controller = ((({let gensym___110836778 = initializers; + (((gensym___110836778) == (null)) ? undefined : gensym___110836778.controller)})) ?? (undefined)); + } + + public __updateStruct(initializers: __Options_CustomDialogExample | undefined): void {} + + private __backing_test?: number | undefined; + + set test(value: number | undefined) { + this.__backing_test = value; + } + + public get test(): number | undefined { + return (this.__backing_test as number | undefined); + } + + private __backing_str?: string; + + set str(value: string) { + this.__backing_str = value; + } + + public get str(): string { + return (this.__backing_str as string); + } + + private __backing_controller?: CustomDialogController | undefined; + + set controller(value: CustomDialogController | undefined) { + this.__backing_controller = value; + } + + public get controller(): CustomDialogController | undefined { + return (this.__backing_controller as CustomDialogController | undefined); + } + + public __setDialogController__(controller: CustomDialogController): void { + this.controller = controller; + } + + public build(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (223048307)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + Column(__memo_context, ((__memo_id) + (111339450)), undefined, (() => { + Text(__memo_context, ((__memo_id) + (112301077)), ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, instance: TextAttribute): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (57298302)), 1); + const __memo_parameter_instance = __memo_scope.param(0, instance); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_instance.value.fontSize(20); + { + __memo_scope.recache(); + return; + } + }), "我是内容"); + Button(__memo_context, ((__memo_id) + (143562775)), ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, instance: ButtonAttribute): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (92536313)), 1); + const __memo_parameter_instance = __memo_scope.param(0, instance); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_instance.value.onClick(((e: ClickEvent) => { + if (((((this.controller) != (undefined))) && (((this.controller) != (null))))) { + ({let gensym%%_67 = this.controller; + (((gensym%%_67) == (null)) ? undefined : gensym%%_67.close())}); + } + })); + { + __memo_scope.recache(); + return; + } + }), "点我关闭弹窗"); + })); + { + __memo_scope.recache(); + return; + } + } + + private constructor() {} + +} + +@Component() final struct MyStateSample extends CustomComponent { + public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type)=> void) | undefined): void {} + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} + + public build(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { + const __memo_scope = __memo_context.scope(((__memo_id) + (85852899)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + Button(__memo_context, ((__memo_id) + (77307688)), ((__memo_context: __memo_context_type, __memo_id: __memo_id_type, instance: ButtonAttribute): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (229079629)), 1); + const __memo_parameter_instance = __memo_scope.param(0, instance); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + __memo_parameter_instance.value.onClick(((e: ClickEvent) => { + let dialogController: CustomDialogController | undefined = undefined; + dialogController = new CustomDialogController(({ + builder: ((__memo_context: __memo_context_type, __memo_id: __memo_id_type): void => { + const __memo_scope = __memo_context.scope(((__memo_id) + (47497983)), 0); + if (__memo_scope.unchanged) { + __memo_scope.cached; + return; + } + CustomDialogExample._instantiateImpl(__memo_context, ((__memo_id) + (2312069)), undefined, ((): CustomDialogExample => { + let newInstance = new CustomDialogExample(); + const dialogController_Temp = dialogController; + newInstance.__setDialogController__((dialogController_Temp as CustomDialogController)); + return newInstance; + }), ({ + test: 1, + str: "hello", + } as __Options_CustomDialogExample)); + { + __memo_scope.recache(); + return; + } + }), + } as CustomDialogControllerOptions), this); + })); + { + __memo_scope.recache(); + return; + } + }), "test"); + { + __memo_scope.recache(); + return; + } + } + + private constructor() {} + +} + +@CustomDialog() export interface __Options_CustomDialogExample { + set test(test: number | undefined | undefined) + + get test(): number | undefined | undefined + set str(str: string | undefined) + + get str(): string | undefined + set controller(controller: CustomDialogController | undefined | undefined) + + get controller(): CustomDialogController | undefined | undefined + +} + +@Component() export interface __Options_MyStateSample { + +} + +`; + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'transform customdialog variable', + [parsedTransform, uiNoRecheck, recheck, memoNoRecheck, recheck], + { + 'checked:customdialog-no-recheck': [testCustomDialogTransformer], + 'checked:memo-no-recheck': [testMemoTransformer], + }, + { + stopAfter: 'checked', + } +);