diff --git a/arkoala/ets-plugin/src/PropertyTranslators.ts b/arkoala/ets-plugin/src/PropertyTranslators.ts index c4ad19893787a7cecc785d2cd57ae002f021c028..610e2ebd40fa5af2db2692ae06e91e4664101b1a 100644 --- a/arkoala/ets-plugin/src/PropertyTranslators.ts +++ b/arkoala/ets-plugin/src/PropertyTranslators.ts @@ -403,7 +403,10 @@ export abstract class PropertyTranslator { ) const backingName = backingFieldName(asIdentifier(this.property.name)) const backingType = ts.factory.createTypeReferenceNode( - this.importer.withRuntimeImport(impl), + (impl === StateImplementation.SyncedProperty) ? + impl : + this.importer.withRuntimeImport(impl), + [originalType] ) return [ @@ -413,7 +416,7 @@ export abstract class PropertyTranslator { } protected plainImplField(): { name: ts.Identifier; type: ts.TypeNode }[] { - const name = backingFieldName(asIdentifier(this.property.name)) + const name = asIdentifier(this.property.name) const type = this.property.type ?? throwError( `Expected struct field to be explicitly typed in arkts 2.0 app: ${this.property.getText()}` ) @@ -434,7 +437,7 @@ export function createStateOf(importer: Importer, type: ts.TypeNode | undefined, class State extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.mutableState) + return this.stateImplField(StateImplementation.MutableState) } override toInitialization(initializers: ts.Identifier) { return this.initializeBacking(initializers) @@ -462,7 +465,7 @@ class State extends PropertyTranslator { export class ClassState extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.mutableState) + return this.stateImplField(StateImplementation.MutableState) } override toInitialization(initializers: ts.Identifier) { @@ -481,7 +484,7 @@ export class ClassState extends PropertyTranslator { class Prop extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.syncedProperty) + return this.stateImplField(StateImplementation.SyncedProperty) } override toInitialization(initializers: ts.Identifier) { @@ -506,7 +509,7 @@ class Prop extends PropertyTranslator { class Link extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.mutableState) + return this.stateImplField(StateImplementation.MutableState) } override toInitialization(initializers: ts.Identifier) { @@ -523,7 +526,7 @@ class Link extends PropertyTranslator { class ObjectLink extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.syncedProperty) + return this.stateImplField(StateImplementation.SyncedProperty) } override toInitialization(initializers: ts.Identifier) { @@ -548,7 +551,7 @@ class ObjectLink extends PropertyTranslator { class Provide extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.mutableState) + return this.stateImplField(StateImplementation.MutableState) } override toInitialization(initializers: ts.Identifier) { @@ -568,7 +571,7 @@ class Provide extends PropertyTranslator { class Consume extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.mutableState) + return this.stateImplField(StateImplementation.MutableState) } override toInitialization(initializers: ts.Identifier) { @@ -614,7 +617,7 @@ class StorageLink extends PropertyTranslator { } class LocalStorageLink extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.mutableState) + return this.stateImplField(StateImplementation.MutableState) } override toInitialization(initializers: ts.Identifier) { @@ -632,7 +635,7 @@ class LocalStorageLink extends PropertyTranslator { } class StorageProp extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.syncedProperty) + return this.stateImplField(StateImplementation.SyncedProperty) } override toInitialization(initializers: ts.Identifier) { @@ -657,7 +660,7 @@ class StorageProp extends PropertyTranslator { } class LocalStorageProp extends PropertyTranslator { override implField(): { name: ts.Identifier; type: ts.TypeNode }[] { - return this.stateImplField(StateImplementation.syncedProperty) + return this.stateImplField(StateImplementation.SyncedProperty) } override toInitialization(initializers: ts.Identifier) { diff --git a/arkoala/ets-plugin/src/utils.ts b/arkoala/ets-plugin/src/utils.ts index 7454cd0ab1840f06050a64809c08d8f53ca8aee4..f9e07df072c2e31eefa977a6eda07211177de8ca 100644 --- a/arkoala/ets-plugin/src/utils.ts +++ b/arkoala/ets-plugin/src/utils.ts @@ -52,8 +52,8 @@ export enum SyncedPropertyConstructor { } export enum StateImplementation { - syncedProperty = "SyncedProperty", - mutableState = "MutableState", + SyncedProperty = "SyncedProperty", + MutableState = "MutableState", } export enum RewriteNames { diff --git a/arkoala/ets-plugin/test/golden/arkts/Rewrite.ts b/arkoala/ets-plugin/test/golden/arkts/Rewrite.ts index 566107af2aa0a2db8e05189bd106dc1b936d56df..7ea1aee4cdef04a3341b15c818c2c69a9bbef101 100644 --- a/arkoala/ets-plugin/test/golden/arkts/Rewrite.ts +++ b/arkoala/ets-plugin/test/golden/arkts/Rewrite.ts @@ -1,7 +1,7 @@ import { AppStorageLinkState, ArkButton, ArkButtonComponent, ArkColumn, ArkColumnComponent, ArkCommonMethodInterface, ArkStructBase, ArkText, ArkTextComponent, Color, CustomDialogController, DialogAlignment, SyncedProperty, bindCustomDialog, contextLocalStateOf, objectLinkState, propState, stateOf } from "@koalaui/arkts-arkui"; import { ArkPageTransitionEnterComponent, ArkPageTransitionExitComponent, LocalStorage, observableProxy } from "@koalaui/arkui-common"; import { registerArkuiEntry } from "@koalaui/arkts-arkui/ohos.router"; -import { MutableState, OnChange, SyncedProperty, contextLocal } from "@koalaui/runtime"; +import { MutableState, OnChange, contextLocal } from "@koalaui/runtime"; export class ArkEntryExampleComponent extends ArkStructBase { private _entry_local_storage_ = new LocalStorage(); __initializeStruct(/**/ @@ -917,7 +917,7 @@ interface OptionsBuilderExample { interface OptionsGlobalBuilderExample { } interface OptionsBuilderParamExample { - backing_foo?: () => {}; + foo?: () => {}; } interface OptionsStylesExample { } @@ -940,10 +940,10 @@ interface OptionsStoragePropExample { prop?: string; } interface OptionsCustomDialogExample { - backing_controller?: CustomDialogController; + controller?: CustomDialogController; } interface OptionsCustomDialogControllerExample { - backing_dialogController?: CustomDialogController; + dialogController?: CustomDialogController; } interface OptionsObjectLinkExample { backing_a?: SyncedProperty; @@ -954,7 +954,7 @@ interface OptionsObjectLinkExampleParent { a?: ObservedExample[]; } interface OptionsPlainPropertyExample { - backing_field?: number; + field?: number; } interface OptionsCallExample { backing_state?: MutableState; diff --git a/arkoala/ets-plugin/test/golden/arkts/Rewrite3.ts b/arkoala/ets-plugin/test/golden/arkts/Rewrite3.ts index 1dc9e5d7fd2ddffe926801951bc0051faa8f4575..ad8e189eeb7be0959ca427a27a11a9a34478f038 100644 --- a/arkoala/ets-plugin/test/golden/arkts/Rewrite3.ts +++ b/arkoala/ets-plugin/test/golden/arkts/Rewrite3.ts @@ -1,6 +1,5 @@ import { ArkStructBase, StorageLinkState, SyncedProperty, propState } from "@koalaui/arkts-arkui"; import { ArkPageTransitionEnterComponent, ArkPageTransitionExitComponent, observableProxy } from "@koalaui/arkui-common"; -import { SyncedProperty } from "@koalaui/runtime"; import { registerArkuiEntry } from "@koalaui/arkts-arkui/ohos.router"; /* * Copyright (c) 2022-2023 Huawei Device Co., Ltd.