From c0d4c0fe3968e73894c4545db794db1bf0fc73bf Mon Sep 17 00:00:00 2001 From: Yuxin Feng Date: Sat, 14 Jun 2025 17:56:51 +0800 Subject: [PATCH] uiplugin add @JSONRename & @JSONStringifyIgnore to @Observed class transform Signed-off-by: Yuxin Feng Change-Id: I7d32d700f9528f167f1c71da1166787fda5e7f54 --- arkui-plugins/common/predefines.ts | 2 + .../observed-track/observed-jsonrename.ets | 37 ++++ .../observed-jsonstringifyignore.ets | 37 ++++ .../objectlink/objectlink-basic.test.ts | 6 +- .../objectlink/objectlink-observed.test.ts | 14 +- .../observed-jsonrename.test.ts | 206 ++++++++++++++++++ .../observed-jsonstringifyignore.test.ts | 206 ++++++++++++++++++ .../observed-track/observed-only.test.ts | 10 +- .../observed-track-class-property.test.ts | 18 +- .../observed-track-complex-type.test.ts | 124 +++++------ .../observed-track-extends.test.ts | 18 +- .../observed-track-implements.test.ts | 10 +- .../observed-track/observed-track.test.ts | 8 +- .../observed-track/track-only.test.ts | 9 +- .../decorators/watch/watch-basic.test.ts | 8 +- .../property-translators/factory.ts | 7 +- .../property-translators/observedTrack.ts | 23 +- 17 files changed, 628 insertions(+), 115 deletions(-) create mode 100644 arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonrename.ets create mode 100644 arkui-plugins/test/demo/mock/decorators/observed-track/observed-jsonstringifyignore.ets create mode 100644 arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonrename.test.ts create mode 100644 arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-jsonstringifyignore.test.ts diff --git a/arkui-plugins/common/predefines.ts b/arkui-plugins/common/predefines.ts index 8825a0df1..c4c21cb76 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', } export enum DecoratorIntrinsicNames { 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 000000000..a9e0cab8c --- /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 000000000..725a7078e --- /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 cacaf3925..49d5aa806 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 aeef2da0e..e624f4d92 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 000000000..0c0fe3dd6 --- /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 000000000..185acfcf9 --- /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 d101740ce..583313c6a 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 4f629bc80..2c20e050f 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 88fe01b05..55ed88e4d 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 468efab24..6c2f2c625 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 8b0a9b8ef..7c2437a18 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 88b006aed..d03d4a902 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 0aa8d19be..3e77d190c 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 46e1fe943..1733c9e6d 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 b28d6ea0e..882a7b4ba 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 7bf4e179a..28d0762e4 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]; } -- Gitee