From 6132cbf02c53602da4b9d1a8a690a68d11c58137 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Mon, 2 Dec 2024 13:26:53 +0300 Subject: [PATCH 1/3] No duplicate SyncedProperty import Signed-off-by: Alexander Gorshenev --- arkoala/ets-plugin/src/PropertyTranslators.ts | 25 +++++++++++-------- arkoala/ets-plugin/src/utils.ts | 4 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/arkoala/ets-plugin/src/PropertyTranslators.ts b/arkoala/ets-plugin/src/PropertyTranslators.ts index c4ad19893..58be544a4 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 [ @@ -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 7454cd0ab..f9e07df07 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 { -- Gitee From e7fe635d900149b38a7ce9ad86d3b9b1db7e4cb7 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Mon, 2 Dec 2024 13:27:23 +0300 Subject: [PATCH 2/3] Name plain property backing field without backing prefix Signed-off-by: Alexander Gorshenev --- arkoala/ets-plugin/src/PropertyTranslators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arkoala/ets-plugin/src/PropertyTranslators.ts b/arkoala/ets-plugin/src/PropertyTranslators.ts index 58be544a4..610e2ebd4 100644 --- a/arkoala/ets-plugin/src/PropertyTranslators.ts +++ b/arkoala/ets-plugin/src/PropertyTranslators.ts @@ -416,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()}` ) -- Gitee From da886e2447dcf03fba3febf2851d64df4a09f229 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Mon, 2 Dec 2024 13:34:48 +0300 Subject: [PATCH 3/3] Updated golden files Signed-off-by: Alexander Gorshenev --- arkoala/ets-plugin/test/golden/arkts/Rewrite.ts | 10 +++++----- arkoala/ets-plugin/test/golden/arkts/Rewrite3.ts | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arkoala/ets-plugin/test/golden/arkts/Rewrite.ts b/arkoala/ets-plugin/test/golden/arkts/Rewrite.ts index 566107af2..7ea1aee4c 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 1dc9e5d7f..ad8e189ee 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. -- Gitee