diff --git a/arkui-plugins/jest-test.config.js b/arkui-plugins/jest-test.config.js index 98b801f7012da41deebf5f3393dcb11d096b4acc..bd3fca4ea4c9be894067f97c6042784ac3128ad4 100644 --- a/arkui-plugins/jest-test.config.js +++ b/arkui-plugins/jest-test.config.js @@ -55,4 +55,7 @@ module.exports = { API_PATH: apiPath, KIT_PATH: kitPath }, + testPathIgnorePatterns: [ + './test/ut/ui-plugins/decorators/resource/', + ], }; diff --git a/arkui-plugins/test/demo/mock/animation/animatable-extend-basic.ets b/arkui-plugins/test/demo/mock/animation/animatable-extend-basic.ets new file mode 100644 index 0000000000000000000000000000000000000000..91cb598ca1c0c6b617ea9cdc17684ad20fea9506 --- /dev/null +++ b/arkui-plugins/test/demo/mock/animation/animatable-extend-basic.ets @@ -0,0 +1,32 @@ +/* + * 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, Color, Curve } from "@ohos.arkui.component" +import { Entry } from "@ohos.arkui.component" + +@Entry +@Component +struct AnimatablePropertyExample { + build() { + Column() { + Text("AnimatableProperty") + .backgroundColor(Color.Red) + .animation({ duration: 2000, curve: Curve.Ease }) + .fontSize(20) + .animation({ duration: 2000, curve: Curve.Ease }) + .width("100%") + } + } +} \ No newline at end of file diff --git a/arkui-plugins/test/demo/mock/double-dollar/double-dollar-griditem.ets b/arkui-plugins/test/demo/mock/double-dollar/double-dollar-griditem.ets new file mode 100644 index 0000000000000000000000000000000000000000..eae3300b835288fced1703253c1fed14e344247c --- /dev/null +++ b/arkui-plugins/test/demo/mock/double-dollar/double-dollar-griditem.ets @@ -0,0 +1,37 @@ +/* + * 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, Entry, Column, Component, $$, Grid, GridItem } from "@ohos.arkui.component" +import { State } from "@ohos.arkui.stateManagement" + +let c: boolean = false + +@Entry +@Component +struct MyStateSample { + @State boo: boolean = true + build() { + Column() { + Grid() { + GridItem() { + Text('nihao') + }.selected($$(this.boo)) + GridItem() { + Text('nihao') + }.selected($$(c)) + } + } + } +} \ No newline at end of file diff --git a/arkui-plugins/test/ut/ui-plugins/animation/animatable-extend-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/animation/animatable-extend-basic.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..bac248f27bc550448ade222eccf6a20291162ce6 --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/animation/animatable-extend-basic.test.ts @@ -0,0 +1,131 @@ + +/* + * 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 ANIMATION_DIR_PATH: string = 'animation'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, ANIMATION_DIR_PATH, 'animatable-extend-basic.ets'), +]; + +const animatableExtendTransform: Plugins = { + name: 'animatable-extend', + parsed: uiTransform().parsed, +}; + +const pluginTester = new PluginTester('test basic animatableExtend transform', buildConfig); + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +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, Color as Color, Curve as Curve } from "@ohos.arkui.component"; + +import { Entry as Entry } from "@ohos.arkui.component"; + +function main() {} + + + +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct AnimatablePropertyExample extends CustomComponent implements PageLifeCycle { + public __initializeStruct(initializers: __Options_AnimatablePropertyExample | undefined, @memo() content: (()=> void) | undefined): void {} + + public __updateStruct(initializers: __Options_AnimatablePropertyExample | undefined): void {} + + @memo() public build() { + Column(undefined, (() => { + Text(((instance: TextAttribute): void => { + instance.animationStart({ + duration: 2000, + curve: Curve.Ease, + }).backgroundColor(Color.Red).animationStop({ + duration: 2000, + curve: Curve.Ease, + }).animationStart({ + duration: 2000, + curve: Curve.Ease, + }).fontSize(20).animationStop({ + duration: 2000, + curve: Curve.Ease, + }).width("100%"); + return; + }), "AnimatableProperty"); + })); + } + + private constructor() {} + +} + +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_AnimatablePropertyExample { + +} + +class __EntryWrapper extends EntryPoint { + @memo() public entry(): void { + AnimatablePropertyExample._instantiateImpl(undefined, (() => { + return new AnimatablePropertyExample(); + })); + } + + public constructor() {} + +} +`; + +const expectedHeader = + ` + __createOrSetAnimatableProperty(functionName: string, value: number | AnimatableArithmetic, callback: ((value: number | AnimatableArithmetic)=> void)): void + `; + +function testAnimatableExtendTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); + expect(parseDumpSrc(this.declContexts?.['arkui.component.common']?.scriptSnapshot ?? '')).toContain(parseDumpSrc(expectedHeader)); +} + +pluginTester.run( + 'test basic animation transform', + [animatableExtendTransform, uiNoRecheck, recheck], + { + checked: [testAnimatableExtendTransformer], + }, + { + stopAfter: 'checked', + tracing: { externalSourceNames: ['arkui.component.common'] }, + } +); diff --git a/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts index 914f3ed27646c2a841d90dc37a67dbfdb0c5a190..faab9e603cbd8fc299ab8731788ca97a20c24471 100644 --- a/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts @@ -43,8 +43,14 @@ import { memo as memo } from "arkui.stateManagement.runtime"; 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, Color as Color, Curve as Curve } from "@ohos.arkui.component"; @@ -55,12 +61,12 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct AnimatablePropertyExample extends CustomComponent { +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct AnimatablePropertyExample extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_AnimatablePropertyExample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_AnimatablePropertyExample | undefined): void {} - @memo() public _build(@memo() style: ((instance: AnimatablePropertyExample)=> AnimatablePropertyExample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_AnimatablePropertyExample | undefined): void { + @memo() public build() { Column(undefined, (() => { Text(((instance: TextAttribute): void => { instance.animationStart({ @@ -85,7 +91,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_AnimatablePropertyExample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_AnimatablePropertyExample { } diff --git a/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts b/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts index 19cdd4ac22d13a2156fd194b8a4e2e230e61a157..d848437c7270c714011750ae76ef489b5095cf9a 100644 --- a/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts @@ -45,14 +45,24 @@ const parsedTransform: Plugins = { }; const expectedParsedScript: string = ` + +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, Builder as Builder, BuilderParam as BuilderParam } from "@ohos.arkui.component"; @Component() final struct CustomContainer extends CustomComponent { @Builder() public closerBuilder() {} + @BuilderParam() public closer: (()=> void) = this.closerBuilder; + public build() {} + public constructor() {} + } @Component() final struct CustomContainerUser extends CustomComponent { @@ -63,21 +73,25 @@ import { Text as Text, Column as Column, Component as Component, Builder as Buil Text("hello"); }; }; - CustomContainer(({} as __Options_CustomContainer)){ + CustomContainer({}){ Column(){}; }; CustomContainer(undefined){}; CustomContainer(); }; } + public constructor() {} + } @Component() export interface __Options_CustomContainer { @BuilderParam() closer?: (()=> void); + } @Component() export interface __Options_CustomContainerUser { + } `; @@ -89,6 +103,10 @@ const expectedBuilderLambdaScript: string = ` import { memo as memo } from "arkui.stateManagement.runtime"; +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, Builder as Builder, BuilderParam as BuilderParam } from "@ohos.arkui.component"; @@ -97,7 +115,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct CustomContainer extends CustomComponent { +@Component() final struct CustomContainer extends CustomComponent { public __initializeStruct(initializers: __Options_CustomContainer | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_closer = ((((({let gensym___38813563 = initializers; (((gensym___38813563) == (null)) ? undefined : gensym___38813563.closer)})) ?? (content))) ?? (this.closerBuilder)) @@ -117,18 +135,18 @@ function main() {} @memo() public closerBuilder() {} - @memo() public _build(@memo() style: ((instance: CustomContainer)=> CustomContainer) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_CustomContainer | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) final struct CustomContainerUser extends CustomComponent { +@Component() final struct CustomContainerUser extends CustomComponent { public __initializeStruct(initializers: __Options_CustomContainerUser | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_CustomContainerUser | undefined): void {} - @memo() public _build(@memo() style: ((instance: CustomContainerUser)=> CustomContainerUser) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_CustomContainerUser | undefined): void { + @memo() public build() { Column(undefined, (() => { CustomContainer._instantiateImpl(undefined, (() => { return new CustomContainer(); @@ -139,7 +157,7 @@ function main() {} })); CustomContainer._instantiateImpl(undefined, (() => { return new CustomContainer(); - }), ({} as __Options_CustomContainer), (() => { + }), {}, (() => { Column(undefined, (() => {})); })); CustomContainer._instantiateImpl(undefined, (() => { @@ -155,14 +173,14 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_CustomContainer { +@Component() export interface __Options_CustomContainer { set closer(@memo() closer: (()=> void) | undefined) get closer(): @memo() (()=> void) | undefined } -@Component({freezeWhenInactive:false}) export interface __Options_CustomContainerUser { +@Component() export interface __Options_CustomContainerUser { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts b/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts index fecec08266d5f3ce21ca417a20da92d38481764b..09d7420cd1325d07776fd8669c8f77ac186edcf7 100644 --- a/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts @@ -43,6 +43,10 @@ import { memo as memo } from "arkui.stateManagement.runtime"; 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 { memo as memo } from "@ohos.arkui.stateManagement"; @@ -66,12 +70,12 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct MM extends CustomComponent { +@Component() final struct MM extends CustomComponent { public __initializeStruct(initializers: __Options_MM | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MM | undefined): void {} - @memo() public _build(@memo() style: ((instance: MM)=> MM) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MM | undefined): void { + @memo() public build() { Column(undefined, (() => { Text(((instance: TextAttribute): void => { style22(cardStyle(instance.height(200).fontColor("#000000"), 600, "#eeeeee").fontSize(60).fontWeight(400)).width(900); @@ -88,7 +92,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MM { +@Component() export interface __Options_MM { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts index ee4f7e9bef3627ab90fefefc8c810ca50cfbe938..ffdf382388d16408bd58bef43d902e0e84ef8191 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts @@ -38,13 +38,22 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; + +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, Entry as Entry, Builder as Builder, BuilderParam as BuilderParam, Column as Column, Text as Text } from "@ohos.arkui.component"; function main() {} -@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { + + +@Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_customBuilderParam = ((((({let gensym___169376706 = initializers; (((gensym___169376706) == (null)) ? undefined : gensym___169376706.customBuilderParam)})) ?? (content))) ?? (this.customBuilder)) @@ -64,7 +73,7 @@ function main() {} @memo() public customBuilder() {} - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + @memo() public build() { this.customBuilderParam(); } @@ -72,7 +81,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_Parent | undefined): void {} @@ -81,20 +90,20 @@ function main() {} Text(undefined, "Parent builder"); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void { + @memo() public build() { Column(undefined, (() => { Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { customBuilderParam: this.componentBuilder, - } as __Options_Child)); + }); Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { customBuilderParam: @memo() (() => { this.componentBuilder(); }), - } as __Options_Child)); + }); Child._instantiateImpl(undefined, (() => { return new Child(); }), (() => { @@ -102,15 +111,20 @@ function main() {} })); })); } + private constructor() {} + } -@Component({freezeWhenInactive:false}) export interface __Options_Child { +@Component() export interface __Options_Child { set customBuilderParam(@memo() customBuilderParam: (()=> void) | undefined) + get customBuilderParam(): @memo() (()=> void) | undefined + } -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts index 13b5b6ca36990c6b68af668351f7fb0c1c7751b1..2eff07da7a52b4d18430850b08b941af39de9a74 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts @@ -38,48 +38,72 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; + +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, Builder as Builder, BuilderParam as BuilderParam } from "@ohos.arkui.component"; function main() {} -@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { + + +@Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_customBuilderParam = ((((({let gensym___169376706 = initializers; (((gensym___169376706) == (null)) ? undefined : gensym___169376706.customBuilderParam)})) ?? (content))) ?? (this.doNothingBuilder)) this.__backing_customBuilderParam2 = ((((({let gensym___14041256 = initializers; (((gensym___14041256) == (null)) ? undefined : gensym___14041256.customBuilderParam2)})) ?? (content))) ?? (this.doNothingBuilder2)) } + public __updateStruct(initializers: __Options_Child | undefined): void {} + private __backing_customBuilderParam?: @memo() (()=> void); + public get customBuilderParam(): @memo() (()=> void) { return this.__backing_customBuilderParam!; } + public set customBuilderParam(@memo() value: (()=> void)) { this.__backing_customBuilderParam = value; } + private __backing_customBuilderParam2?: @memo() ((str: string)=> void); + public get customBuilderParam2(): @memo() ((str: string)=> void) { return this.__backing_customBuilderParam2!; } + public set customBuilderParam2(@memo() value: ((str: string)=> void)) { this.__backing_customBuilderParam2 = value; } + @memo() public doNothingBuilder() {} + @memo() public doNothingBuilder2(str: string) {} - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + + @memo() public build() { this.customBuilderParam(); this.customBuilderParam2("hello"); } + private constructor() {} + } -@Component({freezeWhenInactive:false}) export interface __Options_Child { +@Component() export interface __Options_Child { set customBuilderParam(@memo() customBuilderParam: (()=> void) | undefined) + get customBuilderParam(): @memo() (()=> void) | undefined set customBuilderParam2(@memo() customBuilderParam2: ((str: string)=> void) | undefined) + get customBuilderParam2(): @memo() ((str: string)=> void) | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts index 1c1bf626e6b65a55ca02418f5bc2d0e9cdd6fd66..af94a3af48c3750c9d7771a465320b2760d99809 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts @@ -36,12 +36,20 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; + +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, Row as Row, Builder as Builder, Text as Text } from "@ohos.arkui.component"; function main() {} + @memo() function showTextBuilder() { Text(undefined, "Hello World"); } @@ -52,15 +60,20 @@ function main() {} })); } + class Tmp { public paramA1: string = ""; + public constructor() {} + } -@Component({freezeWhenInactive:false}) final struct BuilderDemo extends CustomComponent { +@Component() final struct BuilderDemo extends CustomComponent { public __initializeStruct(initializers: __Options_BuilderDemo | undefined, @memo() content: (()=> void) | undefined): void {} + public __updateStruct(initializers: __Options_BuilderDemo | undefined): void {} - @memo() public _build(@memo() style: ((instance: BuilderDemo)=> BuilderDemo) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_BuilderDemo | undefined): void { + + @memo() public build() { Row(undefined, @memo() (() => { showTextBuilder(); overBuilder({ @@ -68,10 +81,12 @@ class Tmp { }); })); } + private constructor() {} + } -@Component({freezeWhenInactive:false}) export interface __Options_BuilderDemo { +@Component() export interface __Options_BuilderDemo { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts index 9ea291b7fb7586d1ad41731cc259313a32eacd88..84218864c1e75238e67f8eb67078a576932d316b 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts @@ -41,6 +41,10 @@ import { memo as memo } from "arkui.stateManagement.runtime"; 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 { Component as Component, Column as Column, Builder as Builder, Text as Text } from "@ohos.arkui.component"; @@ -49,7 +53,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct BuilderDemo extends CustomComponent { +@Component() final struct BuilderDemo extends CustomComponent { public __initializeStruct(initializers: __Options_BuilderDemo | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_BuilderDemo | undefined): void {} @@ -68,7 +72,7 @@ function main() {} }), param); } - @memo() public _build(@memo() style: ((instance: BuilderDemo)=> BuilderDemo) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_BuilderDemo | undefined): void { + @memo() public build() { Column(undefined, @memo() (() => { this.showTextBuilder(); this.showTextValueBuilder("Hello @Builder"); @@ -79,7 +83,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_BuilderDemo { +@Component() export interface __Options_BuilderDemo { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts index d11cd83ecc0e8d843fe7c717b4279cbe9d6ef9e3..7c7dadd13307b9b5f8e6cf79f4ad959d09d24290 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts @@ -47,6 +47,10 @@ import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorato import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -57,7 +61,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct LinkParent extends CustomComponent { +@Component() final struct LinkParent extends CustomComponent { public __initializeStruct(initializers: __Options_LinkParent | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___11910109 = initializers; (((gensym___11910109) == (null)) ? undefined : gensym___11910109.__backing_linkVar1)})) { @@ -133,7 +137,7 @@ function main() {} this.__backing_linkVar5!.set(value); } - @memo() public _build(@memo() style: ((instance: LinkParent)=> LinkParent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_LinkParent | undefined): void {} + @memo() public build() {} private constructor() {} @@ -141,7 +145,7 @@ function main() {} @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} -@Component({freezeWhenInactive:false}) export interface __Options_LinkParent { +@Component() export interface __Options_LinkParent { @__Link_intrinsic() set linkVar1(linkVar1: string | undefined) @__Link_intrinsic() get linkVar1(): string | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts index cd0241697f358fdce45ac573d8256ac8c1f2da06..82a452c7729d82ef2c701d6dd1a03b9922169815 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts @@ -47,6 +47,10 @@ import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorato import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -134,7 +138,7 @@ final class LinkType extends BaseEnum { } -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___11910109 = initializers; (((gensym___11910109) == (null)) ? undefined : gensym___11910109.__backing_linkVar1)})) { @@ -308,7 +312,7 @@ final class LinkType extends BaseEnum { this.__backing_linkVar12!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + @memo() public build() {} private constructor() {} @@ -316,7 +320,7 @@ final class LinkType extends BaseEnum { @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { @__Link_intrinsic() set linkVar1(linkVar1: Per | undefined) @__Link_intrinsic() get linkVar1(): Per | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts index 14617528341d80a7214158c2a670efa6b084986c..b8434470e0952e97f43da1115cf0154f27977e40 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts @@ -51,6 +51,10 @@ import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorato import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; +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, Column as Column, TextInput as TextInput } from "@ohos.arkui.component"; @@ -61,7 +65,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct Parant extends CustomComponent { +@Component() final struct Parant extends CustomComponent { public __initializeStruct(initializers: __Options_Parant | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___10127521 = initializers; (((gensym___10127521) == (null)) ? undefined : gensym___10127521.__backing_text1)})) { @@ -81,19 +85,19 @@ function main() {} this.__backing_text1!.set(value); } - @memo() public _build(@memo() style: ((instance: Parant)=> Parant) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parant | undefined): void { + @memo() public build() { Column(undefined, (() => { TextInput(undefined, { text: this.text1, }); Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { __backing_childText: this.__backing_text1, childText2: this.text1, childText3: this.text1, childText4: this.text1, - } as __Options_Child)); + }); })); } @@ -101,7 +105,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { +@Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___161337494 = initializers; (((gensym___161337494) == (null)) ? undefined : gensym___161337494.__backing_childText)})) { @@ -165,7 +169,7 @@ function main() {} this.__backing_childText4!.set(value); } - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + @memo() public build() { TextInput(undefined, { text: this.childText, }); @@ -177,7 +181,7 @@ function main() {} @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} -@Component({freezeWhenInactive:false}) export interface __Options_Parant { +@Component() export interface __Options_Parant { @__Link_intrinsic() set text1(text1: string | undefined) @__Link_intrinsic() get text1(): string | undefined @@ -187,7 +191,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Child { +@Component() export interface __Options_Child { @__Link_intrinsic() set childText(childText: string | undefined) @__Link_intrinsic() get childText(): string | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts index 52ac8cf9772482cf98a40e3ac87a47d96551f5d8..8c1266aa70c029194e135845e7987ce26d09955f 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts @@ -51,8 +51,14 @@ import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateMan import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; +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, Entry as Entry, Column as Column, Button as Button, DatePicker as DatePicker, ClickEvent as ClickEvent } from "@ohos.arkui.component"; @@ -63,7 +69,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct DateComponent extends CustomComponent { +@Component() final struct DateComponent extends CustomComponent { public __initializeStruct(initializers: __Options_DateComponent | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___164314175 = initializers; (((gensym___164314175) == (null)) ? undefined : gensym___164314175.__backing_selectedDate)})) { @@ -83,7 +89,7 @@ function main() {} this.__backing_selectedDate!.set(value); } - @memo() public _build(@memo() style: ((instance: DateComponent)=> DateComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_DateComponent | undefined): void { + @memo() public build() { Column(undefined, (() => { Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { @@ -109,7 +115,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct ParentComponent extends CustomComponent { +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct ParentComponent extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_ParentComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_parentSelectedDate = STATE_MGMT_FACTORY.makeState(this, "parentSelectedDate", ((({let gensym___80922148 = initializers; (((gensym___80922148) == (null)) ? undefined : gensym___80922148.parentSelectedDate)})) ?? (new Date("2021-08-08")))); @@ -127,7 +133,7 @@ function main() {} this.__backing_parentSelectedDate!.set(value); } - @memo() public _build(@memo() style: ((instance: ParentComponent)=> ParentComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ParentComponent | undefined): void { + @memo() public build() { Column(undefined, (() => { Button(((instance: ButtonAttribute): void => { instance.margin(10).onClick(((e: ClickEvent) => { @@ -148,9 +154,9 @@ function main() {} }); DateComponent._instantiateImpl(undefined, (() => { return new DateComponent(); - }), ({ + }), { __backing_selectedDate: this.__backing_parentSelectedDate, - } as __Options_DateComponent)); + }); })); } @@ -160,7 +166,7 @@ function main() {} @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} -@Component({freezeWhenInactive:false}) export interface __Options_DateComponent { +@Component() export interface __Options_DateComponent { @__Link_intrinsic() set selectedDate(selectedDate: Date | undefined) @__Link_intrinsic() get selectedDate(): Date | undefined @@ -170,7 +176,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_ParentComponent { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_ParentComponent { set parentSelectedDate(parentSelectedDate: Date | undefined) get parentSelectedDate(): Date | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts index 49d5aa80618ab037ba3ecdbaf6c1e92aa56b170e..2d94926e1fcc1d7bf1a825e23f3965a8f4ac2ddb 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts @@ -57,6 +57,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -100,7 +104,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@Component() final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_objectlinkvar = STATE_MGMT_FACTORY.makeObjectLink(this, "objectlinkvar", ({let gensym___248819442 = initializers; (((gensym___248819442) == (null)) ? undefined : gensym___248819442.objectlinkvar)})!) @@ -119,13 +123,13 @@ function main() {} return this.__backing_objectlinkvar!.get(); } - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { set objectlinkvar(objectlinkvar: A | undefined) get objectlinkvar(): A | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts index e624f4d9259a0e3dd01c57b23d56897c9a0a27d5..6d7d15fe970acdd6c85f3e3b841af0ee2c1930ad 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts @@ -61,8 +61,14 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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, Entry as Entry, Column as Column, Button as Button, ClickEvent as ClickEvent } from "@ohos.arkui.component"; @@ -158,7 +164,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { +@Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_label = ((({let gensym___171896504 = initializers; (((gensym___171896504) == (null)) ? undefined : gensym___171896504.label)})) ?? ("date")); @@ -189,7 +195,7 @@ function main() {} return this.__backing_data!.get(); } - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + @memo() public build() { Column(undefined, (() => { Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { @@ -204,7 +210,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct Parent extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_newData = STATE_MGMT_FACTORY.makeState(this, "newData", ((({let gensym___225289068 = initializers; (((gensym___225289068) == (null)) ? undefined : gensym___225289068.newData)})) ?? (new NewDate(new DateClass("2023-1-1"))))); @@ -222,14 +228,14 @@ function main() {} this.__backing_newData!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void { + @memo() public build() { Column(undefined, (() => { Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { label: "date", data: this.newData.data, - } as __Options_Child)); + }); Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { this.newData.data = new DateClass("2023-07-07"); @@ -249,7 +255,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Child { +@Component() export interface __Options_Child { set label(label: string | undefined) get label(): string | undefined @@ -262,7 +268,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Parent { set newData(newData: NewDate | undefined) get newData(): NewDate | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonrename.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonrename.test.ts index 0c0fe3dd66de4db92ce3e8097f665fcbb90a2c5b..fc1a79748ed5270d57756d989bf96b7a90114a89 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonrename.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonrename.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -174,18 +178,18 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonstringifyignore.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonstringifyignore.test.ts index 185acfcf94edd2139512f8a16c914638ef23e98a..d0f3da380a87305d2a3dbaa7e3d02e013049c02a 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonstringifyignore.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonstringifyignore.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -174,18 +178,18 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts index 583313c6aeca216e55194fa1b01cede23ec53c59..ff2084e8b2a8bf1df9a56a47110cdcc5873ae551 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -128,18 +132,18 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts index 2c20e050fec066656b98de67afa6bff8650ca478..47add585d1716f0328f9106a0c6332fac14707ee 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -183,18 +187,18 @@ class E implements IObservedObject, ISubscribedWatches { } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts index 55ed88e4db420bda3f632b6484c425ec55580c9f..04589193629951943cd39663a1043938fd8e5c60 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts @@ -55,8 +55,14 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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, Entry as Entry } from "@ohos.arkui.component"; @@ -796,18 +802,18 @@ class mixed3 implements IObservedObject, ISubscribedWatches { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { } diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts index 6c2f2c625546bf3bcb0bc1790a5c92b4a341c28e..fc70f219daf7a44bb6ca481edb56acb8ec4539e9 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -183,18 +187,18 @@ class G extends A { } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts index 7c2437a18557cde4d087461a7e1a4b27273eb1cb..adc83c8a79c71c4e74c3f71248eb4210e453b6f5 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -142,18 +146,18 @@ interface trackInterface { } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts index d03d4a902d7a5b554b5d7fec369a575e775d3380..f9adb205b773d03a2d780c1d8624ba48f223c9c4 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -115,18 +119,18 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts index 3e77d190c3c968cd6d1372f1b7c366ad597fd3fd..bc4a382a0c9f87747b2c3fb7d33215512e995797 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts @@ -55,6 +55,10 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -115,18 +119,18 @@ class C implements IObservedObject, ISubscribedWatches { } -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts index 6343a35d04ec90f2cfd7f0504ae3cfc6cdfc0809..1c1bd66f27611206ee82ff88f77c44da09c35196 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts @@ -45,6 +45,10 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -55,7 +59,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct PropParent extends CustomComponent { +@Component() final struct PropParent extends CustomComponent { public __initializeStruct(initializers: __Options_PropParent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_propVar1 = STATE_MGMT_FACTORY.makeProp(this, "propVar1", ((({let gensym___95172135 = initializers; (((gensym___95172135) == (null)) ? undefined : gensym___95172135.propVar1)})) ?? ("propVar1"))); @@ -142,13 +146,13 @@ function main() {} this.__backing_propVar5!.set(value); } - @memo() public _build(@memo() style: ((instance: PropParent)=> PropParent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_PropParent | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_PropParent { +@Component() export interface __Options_PropParent { set propVar1(propVar1: string | undefined) get propVar1(): string | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts index b21363d41b922108c6700eb27d24be59cc258cd0..58f005ad3c2b27eaac06824a5f6e3931c266c653 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts @@ -45,6 +45,10 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -132,7 +136,7 @@ final class PropType extends BaseEnum { } -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_propVar1 = STATE_MGMT_FACTORY.makeProp(this, "propVar1", ((({let gensym___95172135 = initializers; (((gensym___95172135) == (null)) ? undefined : gensym___95172135.propVar1)})) ?? (new Per(6)))); @@ -331,13 +335,13 @@ final class PropType extends BaseEnum { this.__backing_propVar12!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { set propVar1(propVar1: Per | undefined) get propVar1(): Per | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts index e9ed8c7b66e725c818b04ed44b17f07f90d2e415..411080b4bb43ffd10c6068bdb6dfefc0e17dac84 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts @@ -49,6 +49,10 @@ import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateMan import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; +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, Text as Text, Button as Button, Column as Column, ClickEvent as ClickEvent } from "@ohos.arkui.component"; @@ -59,7 +63,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct CountDownComponent extends CustomComponent { +@Component() final struct CountDownComponent extends CustomComponent { public __initializeStruct(initializers: __Options_CountDownComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_count = STATE_MGMT_FACTORY.makeProp(this, "count", ((({let gensym___58710805 = initializers; (((gensym___58710805) == (null)) ? undefined : gensym___58710805.count)})) ?? (0))); @@ -94,7 +98,7 @@ function main() {} this.__backing_costOfOneAttempt = value; } - @memo() public _build(@memo() style: ((instance: CountDownComponent)=> CountDownComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_CountDownComponent | undefined): void { + @memo() public build() { Column(undefined, (() => { if (((this.count) > (0))) { Text(undefined, (((("You have") + (this.count))) + ("Nuggets left"))); @@ -114,7 +118,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct ParentComponent extends CustomComponent { +@Component() final struct ParentComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ParentComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_countDownStartValue = STATE_MGMT_FACTORY.makeState(this, "countDownStartValue", ((({let gensym___249912438 = initializers; (((gensym___249912438) == (null)) ? undefined : gensym___249912438.countDownStartValue)})) ?? (10))); @@ -132,7 +136,7 @@ function main() {} this.__backing_countDownStartValue!.set(value); } - @memo() public _build(@memo() style: ((instance: ParentComponent)=> ParentComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ParentComponent | undefined): void { + @memo() public build() { Column(undefined, (() => { Text(undefined, (((("Grant") + (this.countDownStartValue))) + ("nuggets to play."))); Button(((instance: ButtonAttribute): void => { @@ -149,10 +153,10 @@ function main() {} }), "-1 - Nuggets in New Game"); CountDownComponent._instantiateImpl(undefined, (() => { return new CountDownComponent(); - }), ({ + }), { count: this.countDownStartValue, costOfOneAttempt: 2, - } as __Options_CountDownComponent)); + }); })); } @@ -160,7 +164,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_CountDownComponent { +@Component() export interface __Options_CountDownComponent { set count(count: number | undefined) get count(): number | undefined @@ -173,7 +177,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_ParentComponent { +@Component() export interface __Options_ParentComponent { set countDownStartValue(countDownStartValue: number | undefined) get countDownStartValue(): number | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts index 0fde11b93065d2225284f011c4cc04b687f30dac..cbde1e66b14ced8147f3406b29d5e44f81e9f24d 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts @@ -45,6 +45,10 @@ import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.st import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -55,7 +59,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct Ancestors extends CustomComponent { +@Component() final struct Ancestors extends CustomComponent { public __initializeStruct(initializers: __Options_Ancestors | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_count = STATE_MGMT_FACTORY.makeProvide(this, "count", "count", ((({let gensym___58710805 = initializers; (((gensym___58710805) == (null)) ? undefined : gensym___58710805.count)})) ?? ("Child0")), false); @@ -157,13 +161,13 @@ function main() {} this.__backing_count7!.set(value); } - @memo() public _build(@memo() style: ((instance: Ancestors)=> Ancestors) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Ancestors | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Ancestors { +@Component() export interface __Options_Ancestors { set count(count: string | undefined | undefined) get count(): string | undefined | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts index 880a40dc2822652957d68d86f53c5e20663dbcea..f201f5fc07d12bee8efb9da2ff1854bcf782f4cf 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts @@ -45,6 +45,10 @@ import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.st import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -55,7 +59,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct PropParent extends CustomComponent { +@Component() final struct PropParent extends CustomComponent { public __initializeStruct(initializers: __Options_PropParent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_provideVar1 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar1", "provideVar1", ((({let gensym___181030638 = initializers; (((gensym___181030638) == (null)) ? undefined : gensym___181030638.provideVar1)})) ?? ("propVar1")), false); @@ -121,13 +125,13 @@ function main() {} this.__backing_provideVar5!.set(value); } - @memo() public _build(@memo() style: ((instance: PropParent)=> PropParent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_PropParent | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_PropParent { +@Component() export interface __Options_PropParent { set provideVar1(provideVar1: string | undefined) get provideVar1(): string | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts index df078fa4ff42e92145de377787fb6f20e40cbff9..ce7a0c814af41d35820e2f2725e0b554263324d6 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts @@ -45,6 +45,10 @@ import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.st import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -132,7 +136,7 @@ final class PropType extends BaseEnum { } -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_provideVar1 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar1", "provideVar1", ((({let gensym___181030638 = initializers; (((gensym___181030638) == (null)) ? undefined : gensym___181030638.provideVar1)})) ?? (new Per(6))), false); @@ -282,13 +286,13 @@ final class PropType extends BaseEnum { this.__backing_provideVar12!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { set provideVar1(provideVar1: Per | undefined) get provideVar1(): Per | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts index 46669ad5595791c79ef5aff6bd81dd0117e1ae29..01004e43251dfa1d726f5589f7a52488c7aae100 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts @@ -47,6 +47,10 @@ import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateMan import { memo as memo } from "arkui.stateManagement.runtime"; +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, Reusable as Reusable } from "@ohos.arkui.component"; @@ -57,24 +61,24 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void { + @memo() public build() { Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { num: 5, - } as __Options_Child), "Child", undefined); + }, "Child", undefined); } private constructor() {} } -@Component({freezeWhenInactive:false}) @Reusable() final struct Child extends CustomComponent { +@Component() @Reusable() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_num = STATE_MGMT_FACTORY.makeProp(this, "num", ((({let gensym___83257243 = initializers; (((gensym___83257243) == (null)) ? undefined : gensym___83257243.num)})) ?? (1))); @@ -117,17 +121,17 @@ function main() {} this.__backing_num1!.set(value); } - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Component() export interface __Options_MyStateSample { } -@Component({freezeWhenInactive:false}) @Reusable() export interface __Options_Child { +@Component() @Reusable() export interface __Options_Child { set num(num: number | undefined) get num(): number | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts index 08e3af89ed1b093b00f78f4328c18811abc3ea64..a5a303ddbc7ce0b8e0b81c2ad95aede8017e83ca 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts @@ -51,8 +51,14 @@ import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; import { ColumnAttribute as ColumnAttribute } from "arkui.component.column"; +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, Entry as Entry, Reusable as Reusable, Column as Column, Text as Text, Button as Button, ClickEvent as ClickEvent, FontWeight as FontWeight } from "@ohos.arkui.component"; @@ -72,7 +78,7 @@ class Message { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { +@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_display = STATE_MGMT_FACTORY.makeState(this, "display", ((({let gensym___83835842 = initializers; (((gensym___83835842) == (null)) ? undefined : gensym___83835842.display)})) ?? (true))); @@ -90,7 +96,7 @@ class Message { this.__backing_display!.set(value); } - @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { + @memo() public build() { Column(((instance: ColumnAttribute): void => { instance.height("100%").width("100%"); return; @@ -104,9 +110,9 @@ class Message { if (this.display) { Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { message: new Message("Child"), - } as __Options_Child), "Child", undefined); + }, "Child", undefined); } })); } @@ -115,7 +121,7 @@ class Message { } -@Reusable() @Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { +@Reusable() @Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_message = STATE_MGMT_FACTORY.makeState(this, "message", ((({let gensym___91869411 = initializers; (((gensym___91869411) == (null)) ? undefined : gensym___91869411.message)})) ?? (new Message("AboutToReuse")))); @@ -144,7 +150,7 @@ class Message { console.info("Recycle ====Child=="); } - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + @memo() public build() { Column(((instance: ColumnAttribute): void => { instance.borderWidth(1).height(100); return; @@ -160,7 +166,7 @@ class Message { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_Index { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Index { set display(display: boolean | undefined) get display(): boolean | undefined @@ -170,7 +176,7 @@ class Message { } -@Reusable() @Component({freezeWhenInactive:false}) export interface __Options_Child { +@Reusable() @Component() export interface __Options_Child { set message(message: Message | undefined) get message(): Message | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts index d595b5a3a951988d724c9d47cee803c54a5cbccd..9db3a8db6c7dc19425d46531e0e55722481ae31c 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts @@ -23,11 +23,11 @@ import { BuildConfig, PluginTestContext } from '../../../../utils/shared-types'; import { uiTransform } from '../../../../../ui-plugins'; import { Plugins } from '../../../../../common/plugin-context'; -const BUILDER_LAMBDA_DIR_PATH: string = 'decorators/state'; +const STATE_DIR_PATH: string = 'decorators/state'; const buildConfig: BuildConfig = mockBuildConfig(); buildConfig.compileFiles = [ - path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'state-basic-type.ets'), + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, STATE_DIR_PATH, 'state-basic-type.ets'), ]; const pluginTester = new PluginTester('test basic type @State decorated variables transformation', buildConfig); @@ -45,6 +45,10 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -55,7 +59,7 @@ function main() {} -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_stateVar1 = STATE_MGMT_FACTORY.makeState(this, "stateVar1", ((({let gensym___213853607 = initializers; (((gensym___213853607) == (null)) ? undefined : gensym___213853607.stateVar1)})) ?? ("stateVar1"))); @@ -121,13 +125,13 @@ function main() {} this.__backing_stateVar5!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { set stateVar1(stateVar1: string | undefined) get stateVar1(): string | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts index f7c74a3e7a579a14fa5322cefec85d095e37b636..cd435d0f14de995b64dee04695ef701725eb5b3e 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts @@ -23,11 +23,11 @@ import { BuildConfig, PluginTestContext } from '../../../../utils/shared-types'; import { uiTransform } from '../../../../../ui-plugins'; import { Plugins } from '../../../../../common/plugin-context'; -const BUILDER_LAMBDA_DIR_PATH: string = 'decorators/state'; +const STATE_DIR_PATH: string = 'decorators/state'; const buildConfig: BuildConfig = mockBuildConfig(); buildConfig.compileFiles = [ - path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'state-complex-type.ets'), + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, STATE_DIR_PATH, 'state-complex-type.ets'), ]; const pluginTester = new PluginTester('test complex type @State decorated variables transformation', buildConfig); @@ -45,6 +45,10 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; +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 } from "@ohos.arkui.component"; @@ -132,7 +136,7 @@ final class StateType extends BaseEnum { } -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_stateVar1 = STATE_MGMT_FACTORY.makeState(this, "stateVar1", ((({let gensym___213853607 = initializers; (((gensym___213853607) == (null)) ? undefined : gensym___213853607.stateVar1)})) ?? (new Per(6)))); @@ -282,13 +286,13 @@ final class StateType extends BaseEnum { this.__backing_stateVar12!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + @memo() public build() {} private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { set stateVar1(stateVar1: Per | undefined) get stateVar1(): Per | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts index f3f46a093ba17f44a7d89d44b58c9ad922faca7f..dd53e3c780810391cf0ef1e16c05865d71b0ec3f 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts @@ -23,11 +23,11 @@ import { BuildConfig, PluginTestContext } from '../../../../utils/shared-types'; import { uiTransform } from '../../../../../ui-plugins'; import { Plugins } from '../../../../../common/plugin-context'; -const BUILDER_LAMBDA_DIR_PATH: string = 'decorators/state'; +const STATE_DIR_PATH: string = 'decorators/state'; const buildConfig: BuildConfig = mockBuildConfig(); buildConfig.compileFiles = [ - path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'state-to-state.ets'), + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, STATE_DIR_PATH, 'state-to-state.ets'), ]; const pluginTester = new PluginTester('test @State decorated variables passing', buildConfig); @@ -45,6 +45,10 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; +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, Column as Column, Text as Text } from "@ohos.arkui.component"; @@ -64,7 +68,7 @@ class Per { } -@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { +@Component() final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_parentVar1 = STATE_MGMT_FACTORY.makeState(this, "parentVar1", ((({let gensym___247315634 = initializers; (((gensym___247315634) == (null)) ? undefined : gensym___247315634.parentVar1)})) ?? (new Per("hello")))); @@ -82,13 +86,13 @@ class Per { this.__backing_parentVar1!.set(value); } - @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void { + @memo() public build() { Column(undefined, (() => { Child._instantiateImpl(undefined, (() => { return new Child(); - }), ({ + }), { childVar1: this.parentVar1, - } as __Options_Child)); + }); })); } @@ -96,7 +100,7 @@ class Per { } -@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { +@Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_childVar1 = STATE_MGMT_FACTORY.makeState(this, "childVar1", ((({let gensym___218939886 = initializers; (((gensym___218939886) == (null)) ? undefined : gensym___218939886.childVar1)})) ?? (new Per("ccc")))); @@ -114,7 +118,7 @@ class Per { this.__backing_childVar1!.set(value); } - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + @memo() public build() { Text(undefined, this.childVar1.str); } @@ -122,7 +126,7 @@ class Per { } -@Component({freezeWhenInactive:false}) export interface __Options_Parent { +@Component() export interface __Options_Parent { set parentVar1(parentVar1: Per | undefined) get parentVar1(): Per | undefined @@ -132,7 +136,7 @@ class Per { } -@Component({freezeWhenInactive:false}) export interface __Options_Child { +@Component() export interface __Options_Child { set childVar1(childVar1: Per | undefined) get childVar1(): Per | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts index 34827c4997715c13722da6a49e0fcf68fc6214ad..1e87fdf904b322c3a623c7b889355e3fc38cd2f3 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts @@ -47,8 +47,14 @@ import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from " 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 { Component as Component, Entry as Entry, Column as Column, Text as Text, ClickEvent as ClickEvent } from "@ohos.arkui.component"; @@ -69,7 +75,7 @@ class Data { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { +@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_storageLink = STATE_MGMT_FACTORY.makeStorageLink(this, "PropA", "storageLink", 1) this.__backing_storageLinkObject = STATE_MGMT_FACTORY.makeStorageLink(this, "PropB", "storageLinkObject", new Data(1)) @@ -97,7 +103,7 @@ class Data { this.__backing_storageLinkObject!.set(value); } - @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { + @memo() public build() { Column(undefined, (() => { Text(((instance: TextAttribute): void => { instance.onClick(((e: ClickEvent) => { @@ -118,7 +124,7 @@ class Data { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_Index { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Index { set storageLink(storageLink: number | undefined) get storageLink(): number | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts index 0dc4a318ed768a8921313b71e974dc82ff437e59..a7c21fac8e6dd2853656f166d0a686eda6d77302 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts @@ -45,8 +45,14 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; +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, Entry as Entry } from "@ohos.arkui.component"; @@ -132,7 +138,7 @@ final class Status extends BaseEnum { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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_arrayA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop1", "arrayA", [1, 2, 3]) this.__backing_objectA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop2", "objectA", {}) @@ -226,13 +232,13 @@ final class Status extends BaseEnum { this.__backing_enumA!.set(value); } - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { set arrayA(arrayA: Array | undefined) get arrayA(): Array | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts index b5c5f0004852723563f19f1eae9c65baa6432d02..01d3053de60ce2b23872c32a06a375f51a955a3d 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts @@ -45,8 +45,14 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; +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, Entry as Entry } from "@ohos.arkui.component"; @@ -57,7 +63,7 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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_numA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop1", "numA", 33) this.__backing_stringA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop2", "stringA", "AA") @@ -96,13 +102,13 @@ function main() {} this.__backing_booleanA!.set(value); } - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { set numA(numA: number | undefined) get numA(): number | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts index cb445a245e5855c2d4087521cd4d44bd8017047d..03c12c361c6048b10d3312b883cd6ae4ce95b7cd 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts @@ -47,8 +47,14 @@ import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from " 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 { Component as Component, Entry as Entry, Column as Column, Text as Text, ClickEvent as ClickEvent } from "@ohos.arkui.component"; @@ -69,7 +75,7 @@ class Data { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { +@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_storageProp = STATE_MGMT_FACTORY.makeStorageProp(this, "PropA", "storageProp", 1) this.__backing_storagePropObject = STATE_MGMT_FACTORY.makeStorageProp(this, "PropB", "storagePropObject", new Data(1)) @@ -97,7 +103,7 @@ class Data { this.__backing_storagePropObject!.set(value); } - @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { + @memo() public build() { Column(undefined, (() => { Text(((instance: TextAttribute): void => { instance.onClick(((e: ClickEvent) => { @@ -118,7 +124,7 @@ class Data { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_Index { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Index { set storageProp(storageProp: number | undefined) get storageProp(): number | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts index fc31881378e315c49a38455829f968a1b9beb4fc..520f03561cea4def28768d95e8614131112904ca 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts @@ -45,8 +45,14 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; +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, Entry as Entry } from "@ohos.arkui.component"; @@ -132,7 +138,7 @@ final class Status extends BaseEnum { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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_arrayB = STATE_MGMT_FACTORY.makeStorageProp>(this, "Prop1", "arrayB", [1, 2, 3]) this.__backing_objectB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop2", "objectB", {}) @@ -226,13 +232,13 @@ final class Status extends BaseEnum { this.__backing_enumB!.set(value); } - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { set arrayB(arrayB: Array | undefined) get arrayB(): Array | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts index ae362590aeb471758c0b306b19d4469913fa938d..62fc938a5e03e6b88e153ce3c48b4f920a5eca68 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts @@ -45,8 +45,14 @@ import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement. import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; +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, Entry as Entry } from "@ohos.arkui.component"; @@ -57,7 +63,7 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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_numB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop1", "numB", 43) this.__backing_stringB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop2", "stringB", "BB") @@ -96,13 +102,13 @@ function main() {} this.__backing_booleanB!.set(value); } - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + @memo() public build() {} private constructor() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { set numB(numB: number | undefined) get numB(): number | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts index 1733c9e6d8e4e1a0a864e566aaa61351fc6cd203..3aa9e80ca61945281fc6f99a885780a62876b1a5 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts @@ -73,8 +73,14 @@ import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement. import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; +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, Entry as Entry } from "@ohos.arkui.component"; @@ -135,7 +141,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { +@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_statevar = STATE_MGMT_FACTORY.makeState(this, "statevar", ((({let gensym___76198660 = initializers; (((gensym___76198660) == (null)) ? undefined : gensym___76198660.statevar)})) ?? ("Hello World")), ((_: string): void => { @@ -258,7 +264,7 @@ function main() {} public ProvideOnChange(propName: string) {} - @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void { + @memo() public build() { Child._instantiateImpl(undefined, (() => { return new Child(); })); @@ -268,7 +274,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { +@Component() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_providevar = STATE_MGMT_FACTORY.makeConsume(this, "providevar", "providevar", ((_: string): void => { this.ConsumeOnChange(_); @@ -289,7 +295,7 @@ function main() {} public ConsumeOnChange(propName: string) {} - @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void {} + @memo() public build() {} private constructor() {} @@ -297,7 +303,7 @@ function main() {} @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { set statevar(statevar: string | undefined) get statevar(): string | undefined @@ -343,7 +349,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_Child { +@Component() export interface __Options_Child { set providevar(providevar: string | undefined) get providevar(): string | undefined diff --git a/arkui-plugins/test/ut/ui-plugins/double-dollar/double-dollar-griditem.test.ts b/arkui-plugins/test/ut/ui-plugins/double-dollar/double-dollar-griditem.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..cb96e7fb1adf004bf7ed95ef2639c6efad438d99 --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/double-dollar/double-dollar-griditem.test.ts @@ -0,0 +1,146 @@ +/* + * 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 { uiNoRecheck, recheck } from '../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; +import { uiTransform } from '../../../../ui-plugins'; +import { Plugins } from '../../../../common/plugin-context'; + +const DOUBLE_DOLLAR_DIR_PATH: string = 'double-dollar'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, DOUBLE_DOLLAR_DIR_PATH, 'double-dollar-griditem.ets'), +]; + +const pluginTester = new PluginTester('test griditem bindable capability', buildConfig); + +const parsedTransform: Plugins = { + name: 'double-dollar-griditem', + parsed: uiTransform().parsed +}; + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { GridItemAttribute as GridItemAttribute } from "arkui.component.gridItem"; + +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, Entry as Entry, Column as Column, Component as Component, $$ as $$, Grid as Grid, GridItem as GridItem } from "@ohos.arkui.component"; + +import { State as State } from "@ohos.arkui.stateManagement"; + +let c: boolean; + +function main() {} + +c = false; + +@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_boo = STATE_MGMT_FACTORY.makeState(this, "boo", ((({let gensym___9142460 = initializers; + (((gensym___9142460) == (null)) ? undefined : gensym___9142460.boo)})) ?? (true))); + } + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} + + private __backing_boo?: IStateDecoratedVariable; + + public get boo(): boolean { + return this.__backing_boo!.get(); + } + + public set boo(value: boolean) { + this.__backing_boo!.set(value); + } + + @memo() public build() { + Column(undefined, (() => { + Grid(undefined, (() => { + GridItem(((instance: GridItemAttribute): void => { + instance.selected($$(this.boo)); + return; + }), (() => { + Text(undefined, "nihao"); + })); + GridItem(((instance: GridItemAttribute): void => { + instance.selected($$(c)); + return; + }), (() => { + Text(undefined, "nihao"); + })); + })); + })); + } + + private constructor() {} + +} + +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_MyStateSample { + set boo(boo: boolean | undefined) + + get boo(): boolean | undefined + set __backing_boo(__backing_boo: IStateDecoratedVariable | undefined) + + get __backing_boo(): IStateDecoratedVariable | undefined + +} + +class __EntryWrapper extends EntryPoint { + @memo() public entry(): void { + MyStateSample._instantiateImpl(undefined, (() => { + return new MyStateSample(); + })); + } + + public constructor() {} + +} +`; + +function testParsedAndCheckedTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test griditem bindable capability', + [parsedTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testParsedAndCheckedTransformer], + }, + { + stopAfter: 'checked', + } +); diff --git a/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts b/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts index a1d525dd7c0d7066ecafa04ee423a8a34350eee3..3a5763d1193ad767677e83b2c34bc66abb5c33c6 100644 --- a/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts @@ -40,57 +40,82 @@ const importParsed: Plugins = { const pluginTester = new PluginTester('test import transform', buildConfig); const expectedParsedScript: string = ` -import { __Options_SimpleStruct as __Options_SimpleStruct } from \"./utils/simple-struct\"; -import { CustomComponent as CustomComponent } from \"arkui.component.customComponent\"; -import { Component as Component, Text as Text } from \"@ohos.arkui.component\"; -import { SimpleStruct as SimpleStruct } from \"./utils/simple-struct\"; + +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, Text as Text } from "@ohos.arkui.component"; + +import { SimpleStruct as SimpleStruct } from "./utils/simple-struct"; @Component() final struct ImportStruct extends CustomComponent { - public build() { - SimpleStruct(); - SimpleStruct(({ - message: \"str1\", - } as __Options_SimpleStruct)); - SimpleStruct(){ - Text(\"a\"); - }; - } - public constructor() {} + public build() { + SimpleStruct(); + SimpleStruct({ + message: "str1", + }); + SimpleStruct(){ + Text("a"); + }; + } + + public constructor() {} + } + @Component() export interface __Options_ImportStruct { + } `; const expectedCheckedScript: string = ` -import { memo as memo } from \"arkui.stateManagement.runtime\"; -import { __Options_SimpleStruct as __Options_SimpleStruct } from \"./utils/simple-struct\"; -import { CustomComponent as CustomComponent } from \"arkui.component.customComponent\"; -import { Component as Component, Text as Text } from \"@ohos.arkui.component\"; -import { SimpleStruct as SimpleStruct } from \"./utils/simple-struct\"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +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, Text as Text } from "@ohos.arkui.component"; + +import { SimpleStruct as SimpleStruct } from "./utils/simple-struct"; function main() {} -@Component({freezeWhenInactive:false}) final struct ImportStruct extends CustomComponent { - public __initializeStruct(initializers: __Options_ImportStruct | undefined, @memo() content: (()=> void) | undefined): void {} - public __updateStruct(initializers: __Options_ImportStruct | undefined): void {} - @memo() public _build(@memo() style: ((instance: ImportStruct)=> ImportStruct) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ImportStruct | undefined): void { - SimpleStruct._instantiateImpl(undefined, (() => { - return new SimpleStruct(); - })); - SimpleStruct._instantiateImpl(undefined, (() => { - return new SimpleStruct(); - }), ({ - message: \"str1\", - } as __Options_SimpleStruct)); - SimpleStruct._instantiateImpl(undefined, (() => { - return new SimpleStruct(); - }), (() => { - Text(undefined, \"a\"); - })); - } - private constructor() {} + + +@Component() final struct ImportStruct extends CustomComponent { + public __initializeStruct(initializers: __Options_ImportStruct | undefined, @memo() content: (()=> void) | undefined): void {} + + public __updateStruct(initializers: __Options_ImportStruct | undefined): void {} + + @memo() public build() { + SimpleStruct._instantiateImpl(undefined, (() => { + return new SimpleStruct(); + })); + SimpleStruct._instantiateImpl(undefined, (() => { + return new SimpleStruct(); + }), { + message: "str1", + }); + SimpleStruct._instantiateImpl(undefined, (() => { + return new SimpleStruct(); + }), (() => { + Text(undefined, "a"); + })); + } + + private constructor() {} + } -@Component({freezeWhenInactive:false}) export interface __Options_ImportStruct { + +@Component() export interface __Options_ImportStruct { + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts b/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts index 6b6b18ca0fa703f05ac2d26af3bf4c05b0ebf601..7ca0f1ec5b94df512fa39902d5c9884744789fa8 100644 --- a/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts @@ -39,8 +39,14 @@ const pluginTester = new PluginTester('test import transform', buildConfig); const expectedParsedScript: string = ` +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 { Prop as Prop, Column as Column, Entry as Entry } from "@kit.ArkUI"; @@ -53,7 +59,7 @@ import { Button as Button } from "arkui.component.button"; import hilog from "@ohos.hilog"; -@Entry() @Component() final struct A extends CustomComponent { +@Entry() @Component() final struct A extends CustomComponent implements PageLifeCycle { @State() public a: string = "str"; @Prop() public b!: string; @@ -101,8 +107,14 @@ import { TextAttribute as TextAttribute } from "arkui.component.text"; import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; +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 { Prop as Prop, Column as Column, Entry as Entry } from "@kit.ArkUI"; @@ -119,7 +131,7 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct A extends CustomComponent { +@Entry({shared:false,storage:"",routeName:""}) @Component() final struct A extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_A | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_a = STATE_MGMT_FACTORY.makeState(this, "a", ((({let gensym___94024326 = initializers; (((gensym___94024326) == (null)) ? undefined : gensym___94024326.a)})) ?? ("str"))); @@ -153,7 +165,7 @@ function main() {} this.__backing_b!.set(value); } - @memo() public _build(@memo() style: ((instance: A)=> A) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_A | undefined): void { + @memo() public build() { Column(undefined, (() => { Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => {})); @@ -170,7 +182,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_A { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_A { set a(a: string | undefined) get a(): string | undefined 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 index 893cdfbc7dd73cf35be72b56b3887378f0fb1160..f3b40bcece0b98715bd4d2c63069162463a8494f 100644 --- a/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts @@ -43,8 +43,14 @@ 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"; @@ -53,7 +59,7 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { +@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())); @@ -71,7 +77,7 @@ function main() {} this.__backing_myXComponentController = value; } - @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { + @memo() public build() { Flex(((instance: FlexAttribute): void => { instance.width("100%").height("100%"); return; @@ -93,7 +99,7 @@ function main() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_Index { +@Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Index { set myXComponentController(myXComponentController: XComponentController | undefined) get myXComponentController(): XComponentController | undefined diff --git a/arkui-plugins/test/utils/artkts-config.ts b/arkui-plugins/test/utils/artkts-config.ts index c218c9086ce8ea92311b747a2fbc715d7fe18949..cbe7f33db63753b400e4884419fdd402b463aa0e 100644 --- a/arkui-plugins/test/utils/artkts-config.ts +++ b/arkui-plugins/test/utils/artkts-config.ts @@ -35,6 +35,7 @@ import { } from './path-config'; import { ArkTSConfigContextCache } from './cache'; import { BuildConfig, CompileFileInfo, DependentModule } from './shared-types'; +import { setUpSoPath } from './global'; export interface ArkTSConfigObject { compilerOptions: { @@ -200,6 +201,7 @@ class MockArktsConfigBuilder implements ArktsConfigBuilder { this.moduleInfos = new Map(); this.mergedAbcFile = path.resolve(this.outputDir, MOCK_OUTPUT_FILE_NAME); + setUpSoPath(this.pandaSdkPath); this.generateModuleInfos(); this.generateArkTSConfigForModules(); this.cacheArkTSConfig(); diff --git a/arkui-plugins/test/utils/compile.ts b/arkui-plugins/test/utils/compile.ts index 1c9640de458c4820b853853508c01ddc8cc02352..46f9fe81bab9df519304eefed4caf601a3aac78e 100644 --- a/arkui-plugins/test/utils/compile.ts +++ b/arkui-plugins/test/utils/compile.ts @@ -15,11 +15,24 @@ import * as arkts from '@koalaui/libarkts'; import EventEmitter from 'events'; -import type { JobInfo, PluginTestContext, ProcessEvent, SingleProgramContext, TraceOptions } from './shared-types'; +import { + CompileStrategy, + JobInfo, + PluginTestContext, + ProcessEvent, + SingleProgramContext, + TraceOptions, +} from './shared-types'; import { MockPluginDriver, stateName } from './plugin-driver'; -import { createCacheContextFromFile, destroyContext, resetConfig } from './global'; +import { + createContextFromString, + createCacheContextFromFile, + destroyContext, + resetConfig, +} from './global'; import { PluginDriver } from './plugin-driver'; import { PluginState, PluginContext, PluginExecutor } from '../../common/plugin-context'; +import { concatObject } from './serializable'; function insertPlugin(driver: PluginDriver, plugin: PluginExecutor | undefined): boolean { const pluginContext: PluginContext = driver.getPluginContext(); @@ -29,40 +42,74 @@ function insertPlugin(driver: PluginDriver, plugin: PluginExecutor | undefined): return true; } +function collectPluginTextContextFromSourceProgram(program: arkts.Program, tracing: TraceOptions): PluginTestContext { + const pluginTestContext: PluginTestContext = {}; + const script: arkts.EtsScript = program.astNode; + pluginTestContext.scriptSnapshot = script.dumpSrc(); + return pluginTestContext; +} + +function collectPluginTextContextFromExternalSource( + externalSources: arkts.ExternalSource[], + tracing: TraceOptions, + matchSourceName: (name: string) => boolean, + useCache?: boolean +) { + let pluginTestContext: PluginTestContext = {}; + const filteredExternalSourceNames: string[] = [...tracing.externalSourceNames]; + const filteredExternalSources = externalSources.filter((source) => { + const name = source.getName(); + const sourceProgram: arkts.Program = source.programs[0]; + const shouldCollectByName = filteredExternalSourceNames.includes(name) || matchSourceName(name); + const shouldCollectByProgram = sourceProgram && (!useCache || sourceProgram.isASTLowered()); + return shouldCollectByName && shouldCollectByProgram; + }); + const declContexts: Record = {}; + filteredExternalSources.forEach((source) => { + const name: string = source.getName(); + const sourceProgram: arkts.Program = source.programs[0]; + if (matchSourceName(name)) { + pluginTestContext = concatObject( + pluginTestContext, + collectPluginTextContextFromSourceProgram(sourceProgram, tracing) + ); + } else { + const sourceTestContext: SingleProgramContext = {}; + const script: arkts.EtsScript = sourceProgram.astNode; + const scriptSnapshot = script.dumpSrc(); + sourceTestContext.scriptSnapshot = scriptSnapshot; + declContexts[name] = sourceTestContext; + } + }); + pluginTestContext.declContexts = declContexts; + return pluginTestContext; +} + function collectPluginTestContext( context: arkts.Context, - isExternal: boolean, - tracing: TraceOptions + compileStrategy: CompileStrategy, + tracing: TraceOptions, + matchSourceName: (name: string) => boolean ): PluginTestContext { - const pluginTestContext: PluginTestContext = {}; + const useCache: boolean = compileStrategy !== CompileStrategy.ABC_WTIH_EXTERNAL; + const canCollectSource: boolean = !useCache || compileStrategy === CompileStrategy.ABC; + const canCollectExternal: boolean = !useCache || compileStrategy === CompileStrategy.EXTERNAL; + let pluginTestContext: PluginTestContext = {}; try { const program: arkts.Program = arkts.getOrUpdateGlobalContext(context.peer).program; // TODO: add error/warning handling after plugin - if (!isExternal) { - const script: arkts.EtsScript = program.astNode; - pluginTestContext.scriptSnapshot = script.dumpSrc(); - } else { - const declContexts: Record = {}; + if (canCollectSource) { + pluginTestContext = concatObject( + pluginTestContext, + collectPluginTextContextFromSourceProgram(program, tracing) + ); + } + if (canCollectExternal) { const externalSources: arkts.ExternalSource[] = program.externalSources; - externalSources - .filter((source) => { - const sourceProgram: arkts.Program = source.programs[0]; - return ( - tracing.externalSourceNames.includes(source.getName()) && - sourceProgram && - sourceProgram.isASTLowered() - ); - }) - .forEach((source) => { - const sourceProgram: arkts.Program = source.programs[0]; - const sourceTestContext: SingleProgramContext = {}; - const name: string = source.getName(); - const script: arkts.EtsScript = sourceProgram.astNode; - const scriptSnapshot = script.dumpSrc(); - sourceTestContext.scriptSnapshot = scriptSnapshot; - declContexts[name] = sourceTestContext; - }); - pluginTestContext.declContexts = declContexts; + pluginTestContext = concatObject( + pluginTestContext, + collectPluginTextContextFromExternalSource(externalSources, tracing, matchSourceName, useCache) + ); } } catch (e) { // Do nothing @@ -71,12 +118,17 @@ function collectPluginTestContext( } } +function buildMatchNameFunc(prefix: string, suffix: string): (name: string) => boolean { + return (name: string): boolean => { + return name.startsWith(`${prefix}.`) && name.endsWith(`.${suffix}`); + }; +} + /** * @param emitter event emitter. * @param jobInfo job info. * @param state the current state. * @param context context for the single file. - * @param isExternal boolean indicates if plugin is compiling external sources. * @param stopAfter state that should stop after running plugins. * @returns boolean indicates whether should proceed to the next state. */ @@ -85,19 +137,21 @@ function runPluginsAtState( jobInfo: JobInfo, state: arkts.Es2pandaContextState, context: arkts.Context, - isExternal: boolean, tracing: TraceOptions, stopAfter?: PluginState ): boolean { const stateStr = stateName(state); const plugins = MockPluginDriver.getInstance().getSortedPlugins(state); + const packageName = jobInfo.buildConfig!.packageName; const fileName = jobInfo.compileFileInfo!.fileName; + const matchSourceName = buildMatchNameFunc(packageName, fileName); + const compileStrategy = jobInfo.isCompileAbc; if (plugins && plugins.length > 0) { plugins.forEach((plugin) => { insertPlugin(MockPluginDriver.getInstance(), plugin); const pluginName: string = plugin.name; const pluginStateId: `${PluginState}:${string}` = `${stateStr}:${pluginName}`; - const pluginTestContext = collectPluginTestContext(context, isExternal, tracing); + const pluginTestContext = collectPluginTestContext(context, compileStrategy, tracing, matchSourceName); emitter.emit('TASK_COLLECT', { jobId: jobInfo.id, pluginStateId, @@ -107,7 +161,7 @@ function runPluginsAtState( }); } const pluginStateId: PluginState = `${stateStr}`; - const pluginTestContext = collectPluginTestContext(context, isExternal, tracing); + const pluginTestContext = collectPluginTestContext(context, compileStrategy, tracing, matchSourceName); emitter.emit('TASK_COLLECT', { jobId: jobInfo.id, pluginStateId, @@ -145,6 +199,48 @@ function createContextForExternalCompilation(jobInfo: JobInfo): arkts.Context { return context; } +function compileAbcWithExternal(emitter: EventEmitter, jobInfo: JobInfo, tracing: TraceOptions): void { + MockPluginDriver.getInstance().initPlugins(jobInfo.plugins ?? []); + const context = createContextFromString(jobInfo.filePaths!); + MockPluginDriver.getInstance().getPluginContext().setContextPtr(context.peer); + const stopAfter = jobInfo.stopAfter!; + let shouldStop = false; + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context.peer); + shouldStop = runPluginsAtState( + emitter, + jobInfo, + arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, + context, + tracing, + stopAfter + ); + if (shouldStop) { + destroyContext(context); + MockPluginDriver.getInstance().clear(); + emitter.emit('TASK_FINISH', { jobId: 'compile-abc-with-external' }); + return; + } + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, context.peer); + shouldStop = runPluginsAtState( + emitter, + jobInfo, + arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, + context, + tracing, + stopAfter + ); + if (shouldStop) { + destroyContext(context); + MockPluginDriver.getInstance().clear(); + emitter.emit('TASK_FINISH', { jobId: 'compile-abc-with-external' }); + return; + } + arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED, context.peer); + destroyContext(context); + MockPluginDriver.getInstance().clear(); + emitter.emit('TASK_FINISH', { jobId: 'compile-abc-with-external' }); +} + function compileAbc(emitter: EventEmitter, jobInfo: JobInfo, tracing: TraceOptions): void { MockPluginDriver.getInstance().initPlugins(jobInfo.plugins ?? []); const context = createContextForAbcCompilation(jobInfo); @@ -157,7 +253,6 @@ function compileAbc(emitter: EventEmitter, jobInfo: JobInfo, traci jobInfo, arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context, - false, tracing, stopAfter ); @@ -172,7 +267,6 @@ function compileAbc(emitter: EventEmitter, jobInfo: JobInfo, traci jobInfo, arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, context, - false, tracing, stopAfter ); @@ -191,12 +285,12 @@ function compileExternalProgram(emitter: EventEmitter, jobInfo: Jo const context = createContextForExternalCompilation(jobInfo); MockPluginDriver.getInstance().getPluginContext().setContextPtr(context.peer); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context.peer); - runPluginsAtState(emitter, jobInfo, arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context, true, tracing); + runPluginsAtState(emitter, jobInfo, arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context, tracing); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, context.peer); - runPluginsAtState(emitter, jobInfo, arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, context, true, tracing); + runPluginsAtState(emitter, jobInfo, arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, context, tracing); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_LOWERED, context.peer); destroyContext(context); MockPluginDriver.getInstance().clear(); } -export { compileAbc, compileExternalProgram }; +export { compileAbcWithExternal, compileAbc, compileExternalProgram }; diff --git a/arkui-plugins/test/utils/global.ts b/arkui-plugins/test/utils/global.ts index 99ac287e3509cfb0e2a1963041d8d57cde8a71f0..28f7a868cad56eebddd40b6e0ac3c67981dfd8d9 100644 --- a/arkui-plugins/test/utils/global.ts +++ b/arkui-plugins/test/utils/global.ts @@ -13,10 +13,15 @@ * limitations under the License. */ +import fs from 'fs' import * as arkts from '@koalaui/libarkts'; import { CompileFileInfo } from './shared-types'; -function createGlobalConfig(fileInfo: CompileFileInfo, isDebug: boolean = true): arkts.Config { +function createGlobalConfig( + fileInfo: CompileFileInfo, + isDebug: boolean = true, + isUseCache: boolean = true +): arkts.Config { const config = [ '_', '--extension', @@ -32,14 +37,18 @@ function createGlobalConfig(fileInfo: CompileFileInfo, isDebug: boolean = true): } config.push(fileInfo.filePath); - arkts.MemInitialize(); + if (isUseCache) { + arkts.MemInitialize(); + } arkts.arktsGlobal.filePath = fileInfo.filePath; return resetConfig(config); } -function destroyGlobalConfig(config: arkts.Config): void { +function destroyGlobalConfig(config: arkts.Config, isUseCache: boolean = true): void { destroyConfig(config); - arkts.MemFinalize(); + if (isUseCache) { + arkts.MemFinalize(); + } } function createGlobalContextPtr(config: arkts.Config, files: string[]): number { @@ -59,6 +68,12 @@ function createCacheContextFromFile( return arkts.Context.createCacheContextFromFile(config.peer, filePath, globalContextPtr, isExternal); } +function createContextFromString(filePaths: string[]): arkts.Context { + const source = fs.readFileSync(filePaths.at(0)!).toString(); + arkts.arktsGlobal.filePath = filePaths.at(0)!; + return arkts.Context.createFromString(source); +} + function resetContext(source: string): void { try { arkts.arktsGlobal.context; @@ -99,14 +114,20 @@ function destroyConfig(config: arkts.Config): void { } } +function setUpSoPath(pandaSdkPath: string): void { + arkts.arktsGlobal.es2panda._SetUpSoPath(pandaSdkPath); +} + export { createGlobalConfig, destroyGlobalConfig, createGlobalContextPtr, destroyGlobalContextPtr, createCacheContextFromFile, + createContextFromString, resetContext, resetConfig, destroyContext, destroyConfig, + setUpSoPath, }; diff --git a/arkui-plugins/test/utils/plugin-tester.ts b/arkui-plugins/test/utils/plugin-tester.ts index 7b5a40dc9082236870be283785b09b4fe183ab1f..d10c4ebd3dea1b553d60ce49a51ba03b6fc23d97 100644 --- a/arkui-plugins/test/utils/plugin-tester.ts +++ b/arkui-plugins/test/utils/plugin-tester.ts @@ -20,14 +20,16 @@ import { CompileFileInfo, PluginStateId, PluginTestContext, + Processor, SingleProgramContext, TraceOptions, } from './shared-types'; import { HashGenerator } from './hash-generator'; -import { TaskProcessor } from './task-processor'; import { PluginTestContextCache } from './cache'; import { Plugins, PluginState } from '../../common/plugin-context'; import { concatObject } from './serializable'; +import { ProcessorBuilder } from './processor-builder'; +import { MainProcessor } from './processors/main-processor'; type TestParams = Parameters; @@ -53,7 +55,7 @@ class PluginTester { private hashId: string; private describe: string; private configBuilder: ArktsConfigBuilder; - private taskProcessor?: TaskProcessor; + private taskProcessor?: Processor; private resolve?: Promise; constructor(describe: string, buildConfig?: BuildConfig) { @@ -97,12 +99,16 @@ class PluginTester { let declContexts: Record = {}; fileNames.forEach((fileName) => { const sourceKey = `${abcKey}:${fileName}`; - const sourceContext = PluginTestContextCache.getInstance().get(sourceKey)!; + const sourceContext = PluginTestContextCache.getInstance().get(sourceKey) ?? {}; + if (!!sourceContext.declContexts) { + declContexts = concatObject(declContexts, sourceContext.declContexts); + delete sourceContext.declContexts; + } sourceContexts[fileName] = sourceContext; const declKey = `${externalKey}:${fileName}`; - const declContext = PluginTestContextCache.getInstance().get(declKey)!; - declContexts = concatObject(declContexts, declContext.declContexts); + const declContext = PluginTestContextCache.getInstance().get(declKey) ?? {}; + declContexts = concatObject(declContexts, declContext.declContexts ?? {}); }); return { sourceContexts, declContexts }; @@ -165,7 +171,12 @@ class PluginTester { } private async compile(plugins: Plugins[], stopAfter?: PluginState, tracing?: TraceOptions): Promise { - this.taskProcessor = new TaskProcessor(this.hashId, this.configBuilder.buildConfig, tracing); + this.taskProcessor = ProcessorBuilder.build( + MainProcessor, + this.hashId, + this.configBuilder.buildConfig, + tracing + ); return this.taskProcessor.invokeWorkers(plugins, stopAfter); } diff --git a/arkui-plugins/test/utils/plugins/builder-lambda-no-recheck.ts b/arkui-plugins/test/utils/plugins/builder-lambda-no-recheck.ts index f7d060b9f81437ff326ceb251ab718cb80d062e5..a770c96b00574186901146a05d6ba5eed9b019f7 100644 --- a/arkui-plugins/test/utils/plugins/builder-lambda-no-recheck.ts +++ b/arkui-plugins/test/utils/plugins/builder-lambda-no-recheck.ts @@ -30,7 +30,7 @@ export const builderLambdaNoRecheck: Plugins = { if (!!contextPtr) { let program = arkts.getOrUpdateGlobalContext(contextPtr).program; script = program.astNode; - const builderLambdaTransformer = new BuilderLambdaTransformer(); + const builderLambdaTransformer = new BuilderLambdaTransformer(this.getProjectConfig()); const programVisitor = new ProgramVisitor({ pluginName: builderLambdaNoRecheck.name, state: arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, diff --git a/arkui-plugins/test/utils/processor-builder.ts b/arkui-plugins/test/utils/processor-builder.ts new file mode 100644 index 0000000000000000000000000000000000000000..bb68e31e64f5f992917ef94a73a71c1472642fc9 --- /dev/null +++ b/arkui-plugins/test/utils/processor-builder.ts @@ -0,0 +1,29 @@ +/* + * 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 { BuildConfig, Processor, TraceOptions } from './shared-types'; + +class ProcessorBuilder { + static build( + Processor: { new (hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions): Processor }, + hashId: string, + buildConfig?: BuildConfig, + tracing?: TraceOptions + ): Processor { + return new Processor(hashId, buildConfig, tracing); + } +} + +export { ProcessorBuilder }; diff --git a/arkui-plugins/test/utils/processors/base-processor.ts b/arkui-plugins/test/utils/processors/base-processor.ts new file mode 100644 index 0000000000000000000000000000000000000000..d60d269e09a9b53ac8715e426d0d40c13da32af6 --- /dev/null +++ b/arkui-plugins/test/utils/processors/base-processor.ts @@ -0,0 +1,65 @@ +/* + * 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 { Plugins, PluginState } from "common/plugin-context"; +import { mockBuildConfig } from "../artkts-config"; +import { ArkTSConfigContextCache } from "../cache"; +import { BuildConfig, CompileFileInfo, Processor, TraceOptions } from "../shared-types"; + +abstract class BaseProcessor implements Processor { + hashId: string; + buildConfig: BuildConfig; + tracing: TraceOptions; + cacheDir: string; + arktsConfigFile: string; + compileFiles: Map; + + constructor(hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions) { + this.hashId = hashId; + this.tracing = tracing ?? { externalSourceNames: [] }; + + const _buildConfig: BuildConfig = buildConfig ?? mockBuildConfig(); + this.buildConfig = _buildConfig; + this.cacheDir = _buildConfig.cachePath; + this.arktsConfigFile = this.getArktsConfigFile(); + this.compileFiles = this.getCompileFiles(); + } + + private getArktsConfigFile(): string { + const arktsConfigFile = ArkTSConfigContextCache.getInstance().get(this.hashId)?.arktsConfigFile; + if (!arktsConfigFile) { + const err = `[${this.hashId}] TaskProcessor cannot get arktsConfigFile`; + console.error(err); + throw new Error(err); + } + return arktsConfigFile; + } + + private getCompileFiles(): Map { + const compileFiles = ArkTSConfigContextCache.getInstance().get(this.hashId)?.compileFiles; + if (!compileFiles) { + const err = `[${this.hashId}] TaskProcessor cannot get compileFiles`; + console.error(err); + throw new Error(err); + } + return compileFiles; + } + + abstract invokeWorkers(plugins: Plugins[], stopAfter?: PluginState): Promise; + + abstract clear(): void; +} + +export { BaseProcessor }; \ No newline at end of file diff --git a/arkui-plugins/test/utils/processors/main-processor.ts b/arkui-plugins/test/utils/processors/main-processor.ts new file mode 100644 index 0000000000000000000000000000000000000000..e033948d713a29c37419cda2695acbbfbc189328 --- /dev/null +++ b/arkui-plugins/test/utils/processors/main-processor.ts @@ -0,0 +1,102 @@ +/* + * 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 EventEmitter from 'events'; +import { + BuildConfig, + CompileFileInfo, + CompileStrategy, + JobInfo, + PluginTestContext, + ProcessEvent, + TraceOptions, +} from '../shared-types'; +import { BaseProcessor } from './base-processor'; +import { PluginTestContextCache } from '../cache'; +import { concatObject, serializable } from '../serializable'; +import { Plugins, PluginState } from '../../../common/plugin-context'; +import { + createGlobalConfig, + destroyGlobalConfig, +} from '../global'; +import { compileAbcWithExternal } from '../compile'; + +class MainProcessor extends BaseProcessor { + filePaths: string[]; + + readonly emitter: EventEmitter = new EventEmitter(); + + constructor(hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions) { + super(hashId, buildConfig, tracing); + this.filePaths = this.getCompileFilePaths(); + } + + private getCompileFilePaths(): string[] { + return Array.from(this.compileFiles.values()).map((fileInfo) => fileInfo.filePath); + } + + private subscribe(): void { + this.emitter.on('TASK_COLLECT', (msg) => { + const sourceType = 'abc'; + const pluginStateId = msg.pluginStateId; + const fileName = msg.fileName; + const pluginTestContext = msg.pluginTestContext as PluginTestContext; + const key = `${this.hashId}:${sourceType}:${pluginStateId}:${fileName}`; + let currentPluginTestContext; + if (PluginTestContextCache.getInstance().has(key)) { + const oldContext = PluginTestContextCache.getInstance().get(key)!; + currentPluginTestContext = concatObject(oldContext, pluginTestContext); + } else { + currentPluginTestContext = pluginTestContext; + } + PluginTestContextCache.getInstance().set(key, currentPluginTestContext); + }); + } + + private assignTask( + fileInfo: CompileFileInfo, + plugins: Plugins[], + stopAfter?: PluginState + ): void { + const jobInfo: JobInfo = { + id: 'compile-abc-with-external', + isCompileAbc: CompileStrategy.ABC_WTIH_EXTERNAL, + compileFileInfo: fileInfo, + buildConfig: serializable(this.buildConfig), + plugins, + stopAfter, + filePaths: this.filePaths + }; + compileAbcWithExternal(this.emitter, jobInfo, this.tracing); + } + + async invokeWorkers(plugins: Plugins[], stopAfter?: PluginState): Promise { + return new Promise((resolve) => { + const fileInfo: CompileFileInfo = this.compileFiles.values().next().value!; + const config = createGlobalConfig(fileInfo, true, false); + this.subscribe(); + this.emitter.on('TASK_FINISH', (msg) => { + console.log('All tasks completed. Exiting...'); + destroyGlobalConfig(config, false); + resolve(); + }); + this.assignTask(fileInfo, plugins, stopAfter); + }); + } + + clear(): void {} +} + +export { MainProcessor }; diff --git a/arkui-plugins/test/utils/task-processor.ts b/arkui-plugins/test/utils/processors/task-processor.ts similarity index 87% rename from arkui-plugins/test/utils/task-processor.ts rename to arkui-plugins/test/utils/processors/task-processor.ts index afaa98fc9ac100e62d170882f4353f79714c16d2..5371d14a38c84b790edf82298c712216b5e784a4 100644 --- a/arkui-plugins/test/utils/task-processor.ts +++ b/arkui-plugins/test/utils/processors/task-processor.ts @@ -18,28 +18,29 @@ import * as fs from 'fs'; import * as path from 'path'; import * as child_process from 'child_process'; import EventEmitter from 'events'; -import type { - BuildConfig, - CompileFileInfo, - JobInfo, - PluginTestContext, - ProcessEvent, - TraceOptions, -} from './shared-types'; -import { mockBuildConfig } from './artkts-config'; +import { + CompileStrategy, + type BuildConfig, + type CompileFileInfo, + type JobInfo, + type PluginTestContext, + type ProcessEvent, + type TraceOptions, +} from '../shared-types'; import { DECL_ETS_SUFFIX, ensurePathExists, getFileName, MOCK_DEP_INPUT_FILE_NAME, MOCK_FILE_DEP_FILE_NAME, -} from './path-config'; -import { ArkTSConfigContextCache, FileDependencyContextCache, PluginTestContextCache } from './cache'; -import { HashGenerator } from './hash-generator'; -import { createGlobalConfig, createGlobalContextPtr, destroyGlobalConfig, destroyGlobalContextPtr } from './global'; -import { Plugins, PluginState } from '../../common/plugin-context'; -import { concatObject, serializable } from './serializable'; -import { compileAbc, compileExternalProgram } from './compile'; +} from '../path-config'; +import { FileDependencyContextCache, PluginTestContextCache } from '../cache'; +import { HashGenerator } from '../hash-generator'; +import { createGlobalConfig, createGlobalContextPtr, destroyGlobalConfig, destroyGlobalContextPtr } from '../global'; +import { Plugins, PluginState } from '../../../common/plugin-context'; +import { concatObject, serializable } from '../serializable'; +import { compileAbc, compileExternalProgram } from '../compile'; +import { BaseProcessor } from './base-processor'; interface Job { id: string; @@ -230,17 +231,11 @@ function addJobToQueues(job: Job, queues: Queues): void { } } -class TaskProcessor { - hashId: string; - buildConfig: BuildConfig; - tracing: TraceOptions; - cacheDir: string; +class TaskProcessor extends BaseProcessor { entryFiles: Set; depAnalyzerPath: string; depInputFile: string; fileDepsInfoJson: string; - arktsConfigFile: string; - compileFiles: Map; jobMap: Record; jobQueues: Queues; @@ -248,18 +243,11 @@ class TaskProcessor { private worker!: WorkerInfo; constructor(hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions) { - this.hashId = hashId; - this.tracing = tracing ?? { externalSourceNames: [] }; - - const _buildConfig: BuildConfig = buildConfig ?? mockBuildConfig(); - this.buildConfig = _buildConfig; - this.cacheDir = _buildConfig.cachePath; - this.entryFiles = new Set(_buildConfig.compileFiles as string[]); - this.depAnalyzerPath = _buildConfig.depAnalyzerPath; - this.depInputFile = path.resolve(_buildConfig.cachePath, this.hashId, MOCK_DEP_INPUT_FILE_NAME); - this.fileDepsInfoJson = path.resolve(_buildConfig.cachePath, this.hashId, MOCK_FILE_DEP_FILE_NAME); - this.arktsConfigFile = this.getArktsConfigFile(); - this.compileFiles = this.getCompileFiles(); + super(hashId, buildConfig, tracing); + this.entryFiles = new Set(this.buildConfig.compileFiles as string[]); + this.depAnalyzerPath = this.buildConfig.depAnalyzerPath; + this.depInputFile = path.resolve(this.buildConfig.cachePath, this.hashId, MOCK_DEP_INPUT_FILE_NAME); + this.fileDepsInfoJson = path.resolve(this.buildConfig.cachePath, this.hashId, MOCK_FILE_DEP_FILE_NAME); this.generateFileDependencies(); this.cacheFileDependencies(); @@ -273,26 +261,6 @@ class TaskProcessor { FileDependencyContextCache.getInstance().set(this.hashId, { depInputFile, fileDepsInfoJson }); } - private getArktsConfigFile(): string { - const arktsConfigFile = ArkTSConfigContextCache.getInstance().get(this.hashId)?.arktsConfigFile; - if (!arktsConfigFile) { - const err = `[${this.hashId}] TaskProcessor cannot get arktsConfigFile`; - console.error(err); - throw new Error(err); - } - return arktsConfigFile; - } - - private getCompileFiles(): Map { - const compileFiles = ArkTSConfigContextCache.getInstance().get(this.hashId)?.compileFiles; - if (!compileFiles) { - const err = `[${this.hashId}] TaskProcessor cannot get compileFiles`; - console.error(err); - throw new Error(err); - } - return compileFiles; - } - private generateFileDependencies(): void { ensurePathExists(this.depInputFile); ensurePathExists(this.fileDepsInfoJson); @@ -431,13 +399,13 @@ class TaskProcessor { job = this.jobQueues.externalProgramQueue.shift()!; jobInfo = { id: job.id, - isCompileAbc: false, + isCompileAbc: CompileStrategy.EXTERNAL, }; } else if (this.jobQueues.abcQueue.length > 0) { job = this.jobQueues.abcQueue.shift()!; jobInfo = { id: job.id, - isCompileAbc: true, + isCompileAbc: CompileStrategy.ABC, }; } @@ -475,9 +443,9 @@ class TaskProcessor { private subscribe() { this.emitter.on('ASSIGN_TASK', (msg) => { const job = msg.jobInfo; - if (job.isCompileAbc) { + if (job.isCompileAbc === CompileStrategy.ABC) { compileAbc(this.emitter, job, this.tracing); - } else { + } else if (job.isCompileAbc === CompileStrategy.EXTERNAL) { compileExternalProgram(this.emitter, job, this.tracing); } this.emitter.emit('TASK_FINISH', { jobId: job.id }); diff --git a/arkui-plugins/test/utils/shared-types.ts b/arkui-plugins/test/utils/shared-types.ts index d713420e55dbb29d5e1e320cd7252ea74bbf166e..415e407be9681d73a934edacd16cd977eadaa0bb 100644 --- a/arkui-plugins/test/utils/shared-types.ts +++ b/arkui-plugins/test/utils/shared-types.ts @@ -76,12 +76,13 @@ export interface DependentModule { export interface JobInfo { id: string; - isCompileAbc: boolean; // TODO: change to enum + isCompileAbc: CompileStrategy; compileFileInfo?: CompileFileInfo; buildConfig?: BuildConfig; plugins?: Plugins[]; globalContextPtr?: number; stopAfter?: PluginState; + filePaths?: string[]; } export interface TraceOptions { @@ -119,3 +120,21 @@ export type ProcessEvents = export type ProcessEvent = { [E in ProcessEvents as E['type']]: Omit[]; }; + +export interface Processor { + hashId: string; + buildConfig: BuildConfig; + tracing: TraceOptions; + cacheDir: string; + arktsConfigFile: string; + compileFiles: Map; + + invokeWorkers(plugins: Plugins[], stopAfter?: PluginState): Promise; + clear(): void; +} + +export enum CompileStrategy { + ABC, + EXTERNAL, + ABC_WTIH_EXTERNAL, +} diff --git a/arkui-plugins/ui-plugins/index.ts b/arkui-plugins/ui-plugins/index.ts index e1131f9469b07db5ae9b4bed03af42299e69bea7..6f0abaaa8187cd44ac5dadd904ce64e28a6a53ce 100644 --- a/arkui-plugins/ui-plugins/index.ts +++ b/arkui-plugins/ui-plugins/index.ts @@ -15,7 +15,6 @@ import * as arkts from '@koalaui/libarkts'; import { ComponentTransformer } from './component-transformer'; -import { PreprocessorTransformer } from './preprocessor-transform'; import { CheckedTransformer } from './checked-transformer'; import { Plugins, PluginContext } from '../common/plugin-context'; import { ProgramVisitor } from '../common/program-visitor'; @@ -75,11 +74,10 @@ function parsedProgramVisit(program: arkts.Program, context: PluginContext): ark } else { debugLog('[CANT SKIP PHASE] phase: ui-parsed, moduleName: ', program.moduleName); const componentTransformer = new ComponentTransformer(); - const preprocessorTransformer = new PreprocessorTransformer(); const programVisitor = new ProgramVisitor({ pluginName: uiTransform.name, state: arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, - visitors: [componentTransformer, preprocessorTransformer], + visitors: [componentTransformer], skipPrefixNames: EXTERNAL_SOURCE_PREFIX_NAMES, pluginContext: context, }); diff --git a/arkui-plugins/ui-plugins/preprocessor-transform.ts b/arkui-plugins/ui-plugins/preprocessor-transform.ts deleted file mode 100644 index 9a8cba2bdb585230e0020ed9b60313668ee39955..0000000000000000000000000000000000000000 --- a/arkui-plugins/ui-plugins/preprocessor-transform.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2022-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 arkts from '@koalaui/libarkts'; -import { AbstractVisitor } from '../common/abstract-visitor'; -import { CustomComponentNames } from './utils'; -import { factory } from './ui-factory'; - -export class PreprocessorTransformer extends AbstractVisitor { - private structInterfaceImport: arkts.ETSImportDeclaration[] = []; - - isCustomConponentDecl(node: arkts.CallExpression): boolean { - const nodeName: string = node.expression.dumpSrc(); - if (arkts.hasGlobalStructInfo(nodeName)) { - return true; - } - return false; - } - - transformComponentCall(node: arkts.CallExpression): arkts.TSAsExpression | arkts.CallExpression { - if (node.arguments.length === 0 && node.trailingBlock) { - return node; - } else if (arkts.isObjectExpression(node.arguments[0])) { - const componentName: string = `${ - CustomComponentNames.COMPONENT_INTERFACE_PREFIX - }${node.expression.dumpSrc()}`; - const newArg = arkts.factory.createTSAsExpression( - node.arguments[0].clone(), - arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart(arkts.factory.createIdentifier(componentName)) - ), - true - ); - return arkts.factory.updateCallExpression(node, node.expression, node.typeArguments, [ - newArg, - ...node.arguments.slice(1), - ]); - } else { - return node; - } - } - - addDependencesImport(node: arkts.ETSImportDeclaration): void { - if (!node.source) return; - node.specifiers.forEach((item: arkts.AstNode) => { - if (!arkts.isImportSpecifier(item) || !item.imported?.name) return; - const importName: string = item.imported.name; - if (arkts.hasGlobalStructInfo(importName)) { - const interfaceName: string = CustomComponentNames.COMPONENT_INTERFACE_PREFIX + importName; - const newImport: arkts.ETSImportDeclaration = arkts.factory.createImportDeclaration( - node.source?.clone(), - [factory.createAdditionalImportSpecifier(interfaceName, interfaceName)], - arkts.Es2pandaImportKinds.IMPORT_KINDS_VALUE, - this.program!, - arkts.Es2pandaImportFlags.IMPORT_FLAGS_NONE - ); - this.structInterfaceImport.push(newImport); - } - }); - } - - updateScriptWithImport(): void { - if (!this.program) { - throw Error('Failed to insert import: Transformer has no program'); - } - - this.structInterfaceImport.forEach((element: arkts.ETSImportDeclaration) => { - arkts.importDeclarationInsert(element, this.program!); - }); - } - - visitor(node: arkts.AstNode): arkts.AstNode { - const newNode = this.visitEachChild(node); - if (arkts.isCallExpression(newNode) && this.isCustomConponentDecl(newNode)) { - return this.transformComponentCall(newNode); - } - if (arkts.isETSImportDeclaration(node)) { - this.addDependencesImport(node); - } else if (arkts.isEtsScript(node)) { - this.updateScriptWithImport(); - } - return newNode; - } -}