diff --git a/arkui-plugins/common/predefines.ts b/arkui-plugins/common/predefines.ts index 7aa7f645dc5471a44986b7e99ad3ab975128d474..7d9a4925c0bf7ea60f044c22f2719af597f006d4 100644 --- a/arkui-plugins/common/predefines.ts +++ b/arkui-plugins/common/predefines.ts @@ -71,6 +71,8 @@ export enum DecoratorNames { LOCAL_STORAGE_LINK = 'LocalStorageLink', REUSABLE = 'Reusable', TRACK = 'Track', + JSONSTRINGIFYIGNORE = 'JSONStringifyIgnore', + JSONRENAME = 'JSONRename', ANIMATABLE_EXTEND = 'AnimatableExtend' } diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonrename.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonrename.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9e0cab8c58ba61b921655638a7026ed035b6625 --- /dev/null +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonrename.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 { Component } from "@ohos.arkui.component" +import { Observed, Track } from "@ohos.arkui.stateManagement" + +@Retention({policy: "SOURCE"}) +export declare @interface TestDecor {} + +@Observed +class testJsonRename { + var1: number = 1 + @Track var2: number = 2 + @JSONRename('name3') var3: number = 3 + @TestDecor var4: number = 4 + @JSONRename('name5') @Track var5: number = 5 + @JSONRename('name6') @TestDecor var6: number = 6 + @TestDecor @Track var7: number = 7 + @JSONRename('name8') @TestDecor @Track var8: number = 8 +} + +@Component +struct MyStateSample { + build() {} +} diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonstringifyignore.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonstringifyignore.ets new file mode 100644 index 0000000000000000000000000000000000000000..725a7078ea034e36ccbbdb0174a337475cfa9545 --- /dev/null +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonstringifyignore.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 { Component } from "@ohos.arkui.component" +import { Observed, Track } from "@ohos.arkui.stateManagement" + +@Retention({policy: "SOURCE"}) +export declare @interface TestDecor {} + +@Observed +class testJSONStringifyIgnore { + var1: number = 1 + @Track var2: number = 2 + @JSONStringifyIgnore var3: number = 3 + @TestDecor var4: number = 4 + @JSONStringifyIgnore @Track var5: number = 5 + @JSONStringifyIgnore @TestDecor var6: number = 6 + @TestDecor @Track var7: number = 7 + @JSONStringifyIgnore @TestDecor @Track var8: number = 8 +} + +@Component +struct MyStateSample { + build() {} +} 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 cacaf39252d69a95c64eaae9e14a93975d0b3dd2..49d5aa80618ab037ba3ecdbaf6c1e92aa56b170e 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 @@ -68,7 +68,7 @@ function main() {} @Observed() class A implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -82,7 +82,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -94,7 +94,7 @@ function main() {} } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} 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 aeef2da0e6b96cd8ee357502c400c5b3ff1615af..e624f4d9259a0e3dd01c57b23d56897c9a0a27d5 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 @@ -74,7 +74,7 @@ function main() {} @Observed() class DateClass extends Date implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -88,7 +88,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -100,7 +100,7 @@ function main() {} } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor(args: number | string) { super(args); @@ -109,7 +109,7 @@ function main() {} } @Observed() class NewDate implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -123,7 +123,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -135,9 +135,9 @@ function main() {} } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_data: DateClass = new DateClass(11); + @JSONRename({newName:"data"}) private __backing_data: DateClass = new DateClass(11); public constructor(data: DateClass) { this.data = data; 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 new file mode 100644 index 0000000000000000000000000000000000000000..0c0fe3dd66de4db92ce3e8097f665fcbb90a2c5b --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonrename.test.ts @@ -0,0 +1,206 @@ +/* + * 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 OBSERVED_DIR_PATH: string = 'decorators/observed-track'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, OBSERVED_DIR_PATH, 'observed-jsonrename.ets'), +]; + +const observedJsonRenameTransform: Plugins = { + name: 'observedJsonRename', + parsed: uiTransform().parsed, +} + +const pluginTester = new PluginTester('test observed class transform with JsonRename annotation', buildConfig); + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component } from "@ohos.arkui.component"; + +import { Observed as Observed, Track as Track } from "@ohos.arkui.stateManagement"; + +function main() {} + + + +@Retention({policy:"SOURCE"}) @interface TestDecor {} + +@Observed() class testJsonRename implements IObservedObject, ISubscribedWatches { + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + + public addWatchSubscriber(watchId: WatchIdType): void { + this.subscribedWatches.addWatchSubscriber(watchId); + } + + public removeWatchSubscriber(watchId: WatchIdType): boolean { + return this.subscribedWatches.removeWatchSubscriber(watchId); + } + + public executeOnSubscribingWatches(propertyName: string): void { + this.subscribedWatches.executeOnSubscribingWatches(propertyName); + } + + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + public var1: number = 1; + + @JSONRename({newName:"var2"}) private __backing_var2: number = 2; + + @JSONStringifyIgnore() private __meta_var2: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + @JSONRename({value:"name3"}) public var3: number = 3; + + @TestDecor() public var4: number = 4; + + @JSONRename({value:"name5"}) private __backing_var5: number = 5; + + @JSONStringifyIgnore() private __meta_var5: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + @JSONRename({value:"name6"}) @TestDecor() public var6: number = 6; + + @TestDecor() @JSONRename({newName:"var7"}) private __backing_var7: number = 7; + + @JSONStringifyIgnore() private __meta_var7: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + @JSONRename({value:"name8"}) @TestDecor() private __backing_var8: number = 8; + + @JSONStringifyIgnore() private __meta_var8: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + public constructor() {} + + public get var2(): number { + this.conditionalAddRef(this.__meta_var2); + return this.__backing_var2; + } + + public set var2(newValue: number) { + if (((this.__backing_var2) !== (newValue))) { + this.__backing_var2 = newValue; + this.__meta_var2.fireChange(); + this.executeOnSubscribingWatches("var2"); + } + } + + public get var5(): number { + this.conditionalAddRef(this.__meta_var5); + return this.__backing_var5; + } + + public set var5(newValue: number) { + if (((this.__backing_var5) !== (newValue))) { + this.__backing_var5 = newValue; + this.__meta_var5.fireChange(); + this.executeOnSubscribingWatches("var5"); + } + } + + public get var7(): number { + this.conditionalAddRef(this.__meta_var7); + return this.__backing_var7; + } + + public set var7(newValue: number) { + if (((this.__backing_var7) !== (newValue))) { + this.__backing_var7 = newValue; + this.__meta_var7.fireChange(); + this.executeOnSubscribingWatches("var7"); + } + } + + public get var8(): number { + this.conditionalAddRef(this.__meta_var8); + return this.__backing_var8; + } + + public set var8(newValue: number) { + if (((this.__backing_var8) !== (newValue))) { + this.__backing_var8 = newValue; + this.__meta_var8.fireChange(); + this.executeOnSubscribingWatches("var8"); + } + } + +} + +@Component({freezeWhenInactive:false}) 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 {} + + private constructor() {} + +} + +@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { + +} +`; + +function testObservedJsonRenameTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test observed only transform', + [observedJsonRenameTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testObservedJsonRenameTransformer], + }, + { + stopAfter: 'checked', + } +); 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 new file mode 100644 index 0000000000000000000000000000000000000000..185acfcf94edd2139512f8a16c914638ef23e98a --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonstringifyignore.test.ts @@ -0,0 +1,206 @@ +/* + * 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 OBSERVED_DIR_PATH: string = 'decorators/observed-track'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, OBSERVED_DIR_PATH, 'observed-jsonstringifyignore.ets'), +]; + +const observedJsonStringifyIgnoreTransform: Plugins = { + name: 'observedJsonStringifyIgnore', + parsed: uiTransform().parsed, +} + +const pluginTester = new PluginTester('test observed class transform with JsonStringifyIgnore annotation', buildConfig); + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component } from "@ohos.arkui.component"; + +import { Observed as Observed, Track as Track } from "@ohos.arkui.stateManagement"; + +function main() {} + + + +@Retention({policy:"SOURCE"}) @interface TestDecor {} + +@Observed() class testJSONStringifyIgnore implements IObservedObject, ISubscribedWatches { + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + + public addWatchSubscriber(watchId: WatchIdType): void { + this.subscribedWatches.addWatchSubscriber(watchId); + } + + public removeWatchSubscriber(watchId: WatchIdType): boolean { + return this.subscribedWatches.removeWatchSubscriber(watchId); + } + + public executeOnSubscribingWatches(propertyName: string): void { + this.subscribedWatches.executeOnSubscribingWatches(propertyName); + } + + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + public var1: number = 1; + + @JSONRename({newName:"var2"}) private __backing_var2: number = 2; + + @JSONStringifyIgnore() private __meta_var2: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + @JSONStringifyIgnore() public var3: number = 3; + + @TestDecor() public var4: number = 4; + + @JSONStringifyIgnore() private __backing_var5: number = 5; + + @JSONStringifyIgnore() private __meta_var5: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + @JSONStringifyIgnore() @TestDecor() public var6: number = 6; + + @TestDecor() @JSONRename({newName:"var7"}) private __backing_var7: number = 7; + + @JSONStringifyIgnore() private __meta_var7: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + @JSONStringifyIgnore() @TestDecor() private __backing_var8: number = 8; + + @JSONStringifyIgnore() private __meta_var8: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + public constructor() {} + + public get var2(): number { + this.conditionalAddRef(this.__meta_var2); + return this.__backing_var2; + } + + public set var2(newValue: number) { + if (((this.__backing_var2) !== (newValue))) { + this.__backing_var2 = newValue; + this.__meta_var2.fireChange(); + this.executeOnSubscribingWatches("var2"); + } + } + + public get var5(): number { + this.conditionalAddRef(this.__meta_var5); + return this.__backing_var5; + } + + public set var5(newValue: number) { + if (((this.__backing_var5) !== (newValue))) { + this.__backing_var5 = newValue; + this.__meta_var5.fireChange(); + this.executeOnSubscribingWatches("var5"); + } + } + + public get var7(): number { + this.conditionalAddRef(this.__meta_var7); + return this.__backing_var7; + } + + public set var7(newValue: number) { + if (((this.__backing_var7) !== (newValue))) { + this.__backing_var7 = newValue; + this.__meta_var7.fireChange(); + this.executeOnSubscribingWatches("var7"); + } + } + + public get var8(): number { + this.conditionalAddRef(this.__meta_var8); + return this.__backing_var8; + } + + public set var8(newValue: number) { + if (((this.__backing_var8) !== (newValue))) { + this.__backing_var8 = newValue; + this.__meta_var8.fireChange(); + this.executeOnSubscribingWatches("var8"); + } + } + +} + +@Component({freezeWhenInactive:false}) 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 {} + + private constructor() {} + +} + +@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { + +} +`; + +function testObservedJsonStringifyIgnoreTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test observed only transform', + [observedJsonStringifyIgnoreTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testObservedJsonStringifyIgnoreTransformer], + }, + { + stopAfter: 'checked', + } +); 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 d101740ce49b33f301bd82f5bd0a108a27c199f3..583313c6aeca216e55194fa1b01cede23ec53c59 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 @@ -66,7 +66,7 @@ function main() {} @Observed() class A implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -80,7 +80,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -92,11 +92,11 @@ function main() {} } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_propA: number = 1; + @JSONRename({newName:"propA"}) private __backing_propA: number = 1; - private __backing_trackA: number = 2; + @JSONRename({newName:"trackA"}) private __backing_trackA: number = 2; public constructor() {} 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 4f629bc8041d2c061745490d4467f793a64f6857..2c20e050fec066656b98de67afa6bff8650ca478 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 @@ -71,7 +71,7 @@ class Info { } class E implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -85,7 +85,7 @@ class E implements IObservedObject, ISubscribedWatches { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -99,9 +99,9 @@ class E implements IObservedObject, ISubscribedWatches { public propE: Info = new Info(); - private __backing_trackE: Info = new Info(); + @JSONRename({newName:"trackE"}) private __backing_trackE: Info = new Info(); - private __meta_trackE: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_trackE: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} @@ -121,7 +121,7 @@ class E implements IObservedObject, ISubscribedWatches { } @Observed() class E1 implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -135,7 +135,7 @@ class E implements IObservedObject, ISubscribedWatches { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -147,11 +147,11 @@ class E implements IObservedObject, ISubscribedWatches { } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_propE1: Info = new Info(); + @JSONRename({newName:"propE1"}) private __backing_propE1: Info = new Info(); - private __backing_trackE1: Info = new Info(); + @JSONRename({newName:"trackE1"}) private __backing_trackE1: Info = new Info(); public constructor() {} 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 88fe01b05226784825eb62f9a8d834b5175f5aa5..55ed88e4db420bda3f632b6484c425ec55580c9f 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 @@ -141,7 +141,7 @@ final class Status extends BaseEnum { } @Observed() class mixed1 implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -155,7 +155,7 @@ final class Status extends BaseEnum { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -167,49 +167,49 @@ final class Status extends BaseEnum { } } - private __backing_numA: number = 33; + @JSONRename({newName:"numA"}) private __backing_numA: number = 33; - private __meta_numA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_numA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_stringA: string = "AA"; + @JSONRename({newName:"stringA"}) private __backing_stringA: string = "AA"; - private __meta_stringA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_stringA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_booleanA: boolean = true; + @JSONRename({newName:"booleanA"}) private __backing_booleanA: boolean = true; - private __meta_booleanA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_booleanA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_arrayA: Array = [1, 2, 3]; + @JSONRename({newName:"arrayA"}) private __backing_arrayA: Array = [1, 2, 3]; - private __meta_arrayA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_arrayA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_objectA: Object = {}; + @JSONRename({newName:"objectA"}) private __backing_objectA: Object = {}; - private __meta_objectA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_objectA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_dateA: Date = new Date("2021-08-08"); + @JSONRename({newName:"dateA"}) private __backing_dateA: Date = new Date("2021-08-08"); - private __meta_dateA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_dateA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_setA: Set = new Set(); + @JSONRename({newName:"setA"}) private __backing_setA: Set = new Set(); - private __meta_setA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_setA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_mapA: Map = new Map(); + @JSONRename({newName:"mapA"}) private __backing_mapA: Map = new Map(); - private __meta_mapA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_mapA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_unionA: string | undefined = ""; + @JSONRename({newName:"unionA"}) private __backing_unionA: string | undefined = ""; - private __meta_unionA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_unionA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_classA: Person = new Person(); + @JSONRename({newName:"classA"}) private __backing_classA: Person = new Person(); - private __meta_classA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_classA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_enumA: Status = Status.NotFound; + @JSONRename({newName:"enumA"}) private __backing_enumA: Status = Status.NotFound; - private __meta_enumA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_enumA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public numB: number = 33; @@ -381,7 +381,7 @@ final class Status extends BaseEnum { } @Observed() class mixed2 implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -395,7 +395,7 @@ final class Status extends BaseEnum { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -407,29 +407,29 @@ final class Status extends BaseEnum { } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_numA: number = 33; + @JSONRename({newName:"numA"}) private __backing_numA: number = 33; - private __backing_stringA: string = "AA"; + @JSONRename({newName:"stringA"}) private __backing_stringA: string = "AA"; - private __backing_booleanA: boolean = true; + @JSONRename({newName:"booleanA"}) private __backing_booleanA: boolean = true; - private __backing_arrayA: Array = [1, 2, 3]; + @JSONRename({newName:"arrayA"}) private __backing_arrayA: Array = [1, 2, 3]; - private __backing_objectA: Object = {}; + @JSONRename({newName:"objectA"}) private __backing_objectA: Object = {}; - private __backing_dateA: Date = new Date("2021-08-08"); + @JSONRename({newName:"dateA"}) private __backing_dateA: Date = new Date("2021-08-08"); - private __backing_setA: Set = new Set(); + @JSONRename({newName:"setA"}) private __backing_setA: Set = new Set(); - private __backing_mapA: Map = new Map(); + @JSONRename({newName:"mapA"}) private __backing_mapA: Map = new Map(); - private __backing_unionA: string | undefined = ""; + @JSONRename({newName:"unionA"}) private __backing_unionA: string | undefined = ""; - private __backing_classA: Person = new Person(); + @JSONRename({newName:"classA"}) private __backing_classA: Person = new Person(); - private __backing_enumA: Status = Status.NotFound; + @JSONRename({newName:"enumA"}) private __backing_enumA: Status = Status.NotFound; public constructor() {} @@ -579,7 +579,7 @@ final class Status extends BaseEnum { } class mixed3 implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -593,7 +593,7 @@ class mixed3 implements IObservedObject, ISubscribedWatches { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -605,49 +605,49 @@ class mixed3 implements IObservedObject, ISubscribedWatches { } } - private __backing_numA: number = 33; + @JSONRename({newName:"numA"}) private __backing_numA: number = 33; - private __meta_numA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_numA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_stringA: string = "AA"; + @JSONRename({newName:"stringA"}) private __backing_stringA: string = "AA"; - private __meta_stringA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_stringA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_booleanA: boolean = true; + @JSONRename({newName:"booleanA"}) private __backing_booleanA: boolean = true; - private __meta_booleanA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_booleanA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_arrayA: Array = [1, 2, 3]; + @JSONRename({newName:"arrayA"}) private __backing_arrayA: Array = [1, 2, 3]; - private __meta_arrayA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_arrayA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_objectA: Object = {}; + @JSONRename({newName:"objectA"}) private __backing_objectA: Object = {}; - private __meta_objectA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_objectA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_dateA: Date = new Date("2021-08-08"); + @JSONRename({newName:"dateA"}) private __backing_dateA: Date = new Date("2021-08-08"); - private __meta_dateA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_dateA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_setA: Set = new Set(); + @JSONRename({newName:"setA"}) private __backing_setA: Set = new Set(); - private __meta_setA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_setA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_mapA: Map = new Map(); + @JSONRename({newName:"mapA"}) private __backing_mapA: Map = new Map(); - private __meta_mapA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_mapA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_unionA: string | undefined = ""; + @JSONRename({newName:"unionA"}) private __backing_unionA: string | undefined = ""; - private __meta_unionA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_unionA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_classA: Person = new Person(); + @JSONRename({newName:"classA"}) private __backing_classA: Person = new Person(); - private __meta_classA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_classA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_enumA: Status = Status.NotFound; + @JSONRename({newName:"enumA"}) private __backing_enumA: Status = Status.NotFound; - private __meta_enumA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_enumA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} 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 468efab24c5f92c134fac7118a6d588736e20c6d..6c2f2c625546bf3bcb0bc1790a5c92b4a341c28e 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 @@ -66,7 +66,7 @@ function main() {} @Observed() class A implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -80,7 +80,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -92,11 +92,11 @@ function main() {} } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_propA: number = 1; + @JSONRename({newName:"propA"}) private __backing_propA: number = 1; - private __backing_trackA: number = 2; + @JSONRename({newName:"trackA"}) private __backing_trackA: number = 2; public constructor() {} @@ -136,7 +136,7 @@ class G extends A { } @Observed() class H extends G implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -150,7 +150,7 @@ class G extends A { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -162,9 +162,9 @@ class G extends A { } } - private __backing_propG: number = 1; + @JSONRename({newName:"propG"}) private __backing_propG: number = 1; - private __meta_propG: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_propG: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} 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 8b0a9b8ef20f4b2e804df937e904b98548c9b142..7c2437a18557cde4d087461a7e1a4b27273eb1cb 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 @@ -80,7 +80,7 @@ interface trackInterface { } @Observed() class F implements PropInterface, trackInterface, IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -94,7 +94,7 @@ interface trackInterface { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -106,11 +106,11 @@ interface trackInterface { } } - private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_propF: number = 1; + @JSONRename({newName:"propF"}) private __backing_propF: number = 1; - private __backing_trackF: number = 2; + @JSONRename({newName:"trackF"}) private __backing_trackF: number = 2; public constructor() {} 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 88b006aed741645eca49bdb61c2849680df71b57..d03d4a902d7a5b554b5d7fec369a575e775d3380 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 @@ -66,7 +66,7 @@ function main() {} @Observed() class B implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -80,7 +80,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -94,9 +94,9 @@ function main() {} public propB: number = 1; - private __backing_trackB: number = 2; + @JSONRename({newName:"trackB"}) private __backing_trackB: number = 2; - private __meta_trackB: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_trackB: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} 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 0aa8d19beadb0c688d5e703b74bf1dbe77e0bec4..3e77d190c3c968cd6d1372f1b7c366ad597fd3fd 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 @@ -38,6 +38,7 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test track only transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; @@ -65,7 +66,7 @@ function main() {} class C implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -79,7 +80,7 @@ class C implements IObservedObject, ISubscribedWatches { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -93,9 +94,9 @@ class C implements IObservedObject, ISubscribedWatches { public propC: number = 1; - private __backing_trackC: number = 2; + @JSONRename({newName:"trackC"}) private __backing_trackC: number = 2; - private __meta_trackC: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_trackC: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} 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 46e1fe9438992c8ed952bcd0139af28735fe609d..1733c9e6d8e4e1a0a864e566aaa61351fc6cd203 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 @@ -86,7 +86,7 @@ function main() {} @Observed() class A implements IObservedObject, ISubscribedWatches { - private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + @JSONStringifyIgnore() private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -100,7 +100,7 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - private ____V1RenderId: RenderIdType = 0; + @JSONStringifyIgnore() private ____V1RenderId: RenderIdType = 0; public setV1RenderId(renderId: RenderIdType): void { this.____V1RenderId = renderId; @@ -114,9 +114,9 @@ function main() {} public propA: string = "hello"; - private __backing_trackA: string = "world"; + @JSONRename({newName:"trackA"}) private __backing_trackA: string = "world"; - private __meta_trackA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + @JSONStringifyIgnore() private __meta_trackA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} diff --git a/arkui-plugins/ui-plugins/property-translators/factory.ts b/arkui-plugins/ui-plugins/property-translators/factory.ts index b28d6ea0e00a7a96315de9ac4edbf62962546d57..882a7b4ba4b20d7bee139341a333b4a6014a7848 100644 --- a/arkui-plugins/ui-plugins/property-translators/factory.ts +++ b/arkui-plugins/ui-plugins/property-translators/factory.ts @@ -19,6 +19,7 @@ import { DecoratorNames, DECORATOR_TYPE_MAP, StateManagementTypes } from '../../ import { factory as UIFactory } from '../ui-factory'; import { collectStateManagementTypeImport, getValueInAnnotation, hasDecorator, removeDecorator } from './utils'; import { addMemoAnnotation, findCanAddMemoFromTypeAnnotation, CustomComponentNames } from '../utils'; +import { annotation } from '../../common/arkts-utils'; export class factory { /** @@ -341,6 +342,7 @@ export class factory { arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, false ); + subscribedWatches.setAnnotations([annotation(DecoratorNames.JSONSTRINGIFYIGNORE)]); collectStateManagementTypeImport(StateManagementTypes.SUBSCRIBED_WATCHES); const addWatchSubscriber = factory.createWatchMethod( @@ -459,6 +461,7 @@ export class factory { arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, false ); + v1RenderId.setAnnotations([annotation(DecoratorNames.JSONSTRINGIFYIGNORE)]); collectStateManagementTypeImport(StateManagementTypes.RENDER_ID_TYPE); const setV1RenderId: arkts.MethodDefinition = factory.setV1RenderId(); return [v1RenderId, setV1RenderId]; @@ -598,7 +601,7 @@ export class factory { */ static createMetaInObservedClass(): arkts.ClassProperty { collectStateManagementTypeImport(StateManagementTypes.MUTABLE_STATE_META); - return arkts.factory.createClassProperty( + const meta = arkts.factory.createClassProperty( arkts.factory.createIdentifier(StateManagementTypes.META), factory.generateStateMgmtFactoryCall(StateManagementTypes.MAKE_MUTABLESTATE_META, undefined, [], false), arkts.factory.createTypeReference( @@ -609,6 +612,8 @@ export class factory { arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, false ); + meta.setAnnotations([annotation(DecoratorNames.JSONSTRINGIFYIGNORE)]); + return meta; } /** diff --git a/arkui-plugins/ui-plugins/property-translators/observedTrack.ts b/arkui-plugins/ui-plugins/property-translators/observedTrack.ts index 7bf4e179a90416492e76429189f29b8c48b6487d..28d0762e4cf5c86cf6941f186b4f3db1cd69ed09 100644 --- a/arkui-plugins/ui-plugins/property-translators/observedTrack.ts +++ b/arkui-plugins/ui-plugins/property-translators/observedTrack.ts @@ -14,9 +14,9 @@ */ import * as arkts from '@koalaui/libarkts'; -import { backingField, expectName } from '../../common/arkts-utils'; +import { annotation, backingField, expectName } from '../../common/arkts-utils'; import { DecoratorNames, StateManagementTypes } from '../../common/predefines'; -import { collectStateManagementTypeImport, hasDecorator } from './utils'; +import { collectStateManagementTypeImport, hasDecorator, hasDecoratorName, removeDecorator } from './utils'; import { ClassScopeInfo } from './types'; import { factory } from './factory'; @@ -54,10 +54,29 @@ export class ObservedTrackTranslator { arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE, false ); + const annotations: arkts.AnnotationUsage[] = [...this.property.annotations]; + if ( + !hasDecoratorName(this.property, DecoratorNames.JSONSTRINGIFYIGNORE) && + !hasDecoratorName(this.property, DecoratorNames.JSONRENAME)) { + annotations.push( + annotation(DecoratorNames.JSONRENAME).addProperty( + arkts.factory.createClassProperty( + arkts.factory.createIdentifier('newName'), + arkts.factory.createStringLiteral(originalName), + undefined, + arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_NONE, + false + ) + ) + ); + } + backingField.setAnnotations(annotations); + removeDecorator(backingField, DecoratorNames.TRACK); if (!this.isTracked) { return [backingField]; } const metaField = this.metaField(originalName); + metaField.setAnnotations([annotation(DecoratorNames.JSONSTRINGIFYIGNORE)]); return [backingField, metaField]; }