diff --git a/arkoala/arkui-types/index-full.d.ts b/arkoala/arkui-types/index-full.d.ts index a4386b04d92c7f1cadd8f7ff1cbea29c16a6c55a..209353a2d241ee37a3c77d0f97a07c436c947837 100644 --- a/arkoala/arkui-types/index-full.d.ts +++ b/arkoala/arkui-types/index-full.d.ts @@ -16,6 +16,8 @@ // WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! +declare function $$ (value: T): T + declare const Component: ClassDecorator & ((options: ComponentOptions) => ClassDecorator); declare const ComponentV2: ClassDecorator & ((options: ComponentOptions) => ClassDecorator); diff --git a/arkoala/ets-plugin/src/ArkExpander.ts b/arkoala/ets-plugin/src/ArkExpander.ts index c5cdf8d6e8a975e3730a119321170ae3b4f4ecb2..4ea4d31c719fc7fad85b02db519a9125a7dffa0e 100644 --- a/arkoala/ets-plugin/src/ArkExpander.ts +++ b/arkoala/ets-plugin/src/ArkExpander.ts @@ -33,6 +33,7 @@ import { CallTransformer } from './CallTransformer' import { DebugVisitor } from './AbstractVisitor' import { LegacyCallTransformer } from './LegacyCallTransformer' import { AbilityTransformer } from './AbilityTransformer' +import { DollarDollarTransformer } from "./DollarDollarTransformer" import { ObservedResolver } from "./ObservedResolver" interface ArkToKoOptions { @@ -110,67 +111,69 @@ export function arkExpandFile( moduleInfo?: (moduleName: string) => any, applicationInfo?: ApplicationInfo ): ts.SourceFile { - const importer = new Importer(arkuiPackage, moduleInfo) - const nameTable = new NameTable() - const issueTable = new IssueTable() - const callTable = new CallTable() + const importer = new Importer(arkuiPackage, moduleInfo) + const nameTable = new NameTable() + const issueTable = new IssueTable() + const callTable = new CallTable() - /* Uncomment to dump AST on entry */ + /* Uncomment to dump AST on entry */ - // const debug = new DebugVisitor(sourceFile, ctx) - // debug.visitor(sourceFile) + // const debug = new DebugVisitor(sourceFile, ctx) + // debug.visitor(sourceFile) // resolve identifiers automatically imported from index-full.d.ts - new EtsIdentifierResolver(sourceFile, ctx, typeChecker, importer) - .visitor(sourceFile) - - const callTransformer = new CallTransformer(sourceFile, ctx, typeChecker, callTable, importer) - const lazyTransformer = new LazyTransformer(sourceFile, ctx, importer, callTable) - const newTransformer = new NewTransformer(sourceFile, ctx, importer, issueTable) - const customBuilderTransformer = new CustomBuilderTransformer(sourceFile, ctx, typeChecker, callTable) - const legacyCallTransformer = new LegacyCallTransformer(sourceFile, ctx, importer, callTable) - const extensionStylesTransformer = new ExtensionStylesTransformer(sourceFile, ctx, typeChecker, importer) - const preprocessorTransformer = new EtsFirstArgTransformer(sourceFile, ctx, importer, callTable) - const styleTransformer = new StyleTransformer(sourceFile, ctx, typeChecker, importer, extensionStylesTransformer, callTable) - const structTransformer = new StructTransformer(sourceFile, ctx, typeChecker, importer, nameTable, entryTracker, callTable, extras) - const nameCollector = new NameCollector(sourceFile, ctx, nameTable, issueTable) - const dollarTransformer = new DollarTransformer(sourceFile, ctx, nameTable, importer, applicationInfo) - const abilityTransformer = new AbilityTransformer(sourceFile, ctx, importer) - const observedResolver = new ObservedResolver(sourceFile, ctx, importer) - - nameCollector.visitor(sourceFile) - - const translatedCalls = callTransformer.visitor(sourceFile) as ts.SourceFile - const translatedDollar = dollarTransformer.visitor(translatedCalls) as ts.SourceFile - const translatedLazy = lazyTransformer.visitor(translatedDollar) as ts.SourceFile - const translatedNew = newTransformer.visitor(translatedLazy) as ts.SourceFile - const translatedCustomBuilders = customBuilderTransformer.visitor(translatedNew) as ts.SourceFile - const translatedLegacyCalls = legacyCallTransformer.visitor(translatedCustomBuilders) as ts.SourceFile - const translatedStyleFunctions = extensionStylesTransformer.visitor(translatedLegacyCalls) as ts.SourceFile - const preprocessedEts = preprocessorTransformer.visitor(translatedStyleFunctions) as ts.SourceFile - const translatedStyle = styleTransformer.visitor(preprocessedEts) as ts.SourceFile - const translatedStruct = structTransformer.visitor(translatedStyle) as ts.SourceFile - const translatedAbility = abilityTransformer.visitor(translatedStruct) as ts.SourceFile - const resolvedObserved = observedResolver.visitor(translatedAbility) as ts.SourceFile - - const finalStage = resolvedObserved - - filterOutDiagnostics(sourceFile, nameTable, issueTable, extras) - - return ts.factory.updateSourceFile( - finalStage, - [ - ...importer.generate(), - ...finalStage.statements, - // TODO: do we need a better way to obtain it? - // ...structTranslator.entryCode - ], - finalStage.isDeclarationFile, - finalStage.referencedFiles, - finalStage.typeReferenceDirectives, - finalStage.hasNoDefaultLib, - finalStage.libReferenceDirectives - ) + new EtsIdentifierResolver(sourceFile, ctx, typeChecker, importer) + .visitor(sourceFile) + + const dollarDollarTransformer = new DollarDollarTransformer(sourceFile, ctx) + const callTransformer = new CallTransformer(sourceFile, ctx, typeChecker, callTable, importer) + const lazyTransformer = new LazyTransformer(sourceFile, ctx, importer, callTable) + const newTransformer = new NewTransformer(sourceFile, ctx, importer, issueTable) + const customBuilderTransformer = new CustomBuilderTransformer(sourceFile, ctx, typeChecker, callTable) + const legacyCallTransformer = new LegacyCallTransformer(sourceFile, ctx, importer, callTable) + const extensionStylesTransformer = new ExtensionStylesTransformer(sourceFile, ctx, typeChecker, importer) + const preprocessorTransformer = new EtsFirstArgTransformer(sourceFile, ctx, importer, callTable) + const styleTransformer = new StyleTransformer(sourceFile, ctx, typeChecker, importer, extensionStylesTransformer, callTable) + const structTransformer = new StructTransformer(sourceFile, ctx, typeChecker, importer, nameTable, entryTracker, callTable, extras) + const nameCollector = new NameCollector(sourceFile, ctx, nameTable, issueTable) + const dollarTransformer = new DollarTransformer(sourceFile, ctx, nameTable, importer, applicationInfo) + const abilityTransformer = new AbilityTransformer(sourceFile, ctx, importer) + const observedResolver = new ObservedResolver(sourceFile, ctx, importer) + + nameCollector.visitor(sourceFile) + + const translatedDollarDollar = dollarDollarTransformer.visitor(sourceFile) as ts.SourceFile + const translatedCalls = callTransformer.visitor(translatedDollarDollar) as ts.SourceFile + const translatedDollar = dollarTransformer.visitor(translatedCalls) as ts.SourceFile + const translatedLazy = lazyTransformer.visitor(translatedDollar) as ts.SourceFile + const translatedNew = newTransformer.visitor(translatedLazy) as ts.SourceFile + const translatedCustomBuilders = customBuilderTransformer.visitor(translatedNew) as ts.SourceFile + const translatedLegacyCalls = legacyCallTransformer.visitor(translatedCustomBuilders) as ts.SourceFile + const translatedStyleFunctions = extensionStylesTransformer.visitor(translatedLegacyCalls) as ts.SourceFile + const preprocessedEts = preprocessorTransformer.visitor(translatedStyleFunctions) as ts.SourceFile + const translatedStyle = styleTransformer.visitor(preprocessedEts) as ts.SourceFile + const translatedStruct = structTransformer.visitor(translatedStyle) as ts.SourceFile + const translatedAbility = abilityTransformer.visitor(translatedStruct) as ts.SourceFile + const resolvedObserved = observedResolver.visitor(translatedAbility) as ts.SourceFile + + const finalStage = resolvedObserved + + filterOutDiagnostics(sourceFile, nameTable, issueTable, extras) + + return ts.factory.updateSourceFile( + finalStage, + [ + ...importer.generate(), + ...finalStage.statements, + // TODO: do we need a better way to obtain it? + // ...structTranslator.entryCode + ], + finalStage.isDeclarationFile, + finalStage.referencedFiles, + finalStage.typeReferenceDirectives, + finalStage.hasNoDefaultLib, + finalStage.libReferenceDirectives + ) } export default function arkExpander(program: ts.Program, userPluginOptions: ArkToKoOptions, extras: ts.TransformerExtras) { diff --git a/arkoala/ets-plugin/src/CallTransformer.ts b/arkoala/ets-plugin/src/CallTransformer.ts index 78cae77ec41d61da33f9cc7c1f5ac47f443fa971..e1a2d6a33bbb82634dcb676c1422f12c416d9909 100644 --- a/arkoala/ets-plugin/src/CallTransformer.ts +++ b/arkoala/ets-plugin/src/CallTransformer.ts @@ -91,7 +91,6 @@ export class CallTransformer extends AbstractVisitor { * - it is not user defined */ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) { - const func = node.expression const name = ts.idText(func) if (isBuiltinComponentName(this.ctx, name)) { diff --git a/arkoala/ets-plugin/src/DollarDollarTransformer.ts b/arkoala/ets-plugin/src/DollarDollarTransformer.ts new file mode 100644 index 0000000000000000000000000000000000000000..1890c27a420c77d2099e4007854711db2af6a557 --- /dev/null +++ b/arkoala/ets-plugin/src/DollarDollarTransformer.ts @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2024 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 ts from "@koalaui/ets-tsc" +import { AbstractVisitor } from "./AbstractVisitor" +import { DollarDollar, isDefined } from "./utils" +import { + isComponentMethodCall, + isInitializerObject, + dollarDollarViablePasses +} from "./arkui-knowledge-base/dollar-dollar-viable-passes" + +type Initialization = { parameter: string, type: ts.TypeNode, initializer: ts.Expression } + +export class DollarDollarTransformer extends AbstractVisitor { + private static callExpressionName(node: ts.CallExpression | ts.EtsComponentExpression): string | undefined { + if (!ts.isIdentifier(node.expression)) { + return undefined + } + return ts.idText(node.expression) + } + + private static isDollarDollar(node: ts.CallExpression): boolean { + if (!ts.isIdentifier(node.expression)) { + return false + } + if (node.arguments.length !== 1) { + return false + } + if (ts.idText(node.expression) !== DollarDollar) { + return false + } + return true + } + + visitor(beforeChildren: ts.Node): ts.Node { + const node = this.visitEachChild(beforeChildren) + if (ts.isCallExpression(node)) { + const initializations = DollarDollarTransformer.componentMethodCallInitializations(node) + // TODO + } + if (ts.isEtsComponentExpression(node)) { + return DollarDollarTransformer.componentCallInitializations(node) + .map(it => + (node: ts.EtsComponentExpression | ts.CallExpression) => + DollarDollarTransformer.addOnChanged(node, it) + ) + .reduce( + (addTo, add) => add(addTo), + node as ts.EtsComponentExpression | ts.CallExpression + ) + } + return node + } + + static addOnChanged(node: ts.EtsComponentExpression | ts.CallExpression, initialization: Initialization): ts.CallExpression { + return ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + node, + `__OnChanged_${initialization.parameter}`, + ), + undefined, + [ + ts.factory.createArrowFunction( + undefined, + undefined, + [ + ts.factory.createParameterDeclaration( + undefined, + undefined, + initialization.parameter, + undefined, + initialization.type + ) + ], + ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword), + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ + ts.factory.createExpressionStatement( + ts.factory.createAssignment( + initialization.initializer, + ts.factory.createIdentifier(initialization.parameter) + ) + ) + ], + false + ) + ) + ] + ) + } + + static componentCallInitializations(node: ts.EtsComponentExpression): Initialization[] { + const singleArgument = node.arguments[0] + if (singleArgument === undefined) { + return [] + } + if (!ts.isObjectLiteralExpression(singleArgument)) { + return [] + } + + const viablePasses = dollarDollarViablePasses + .filter(isInitializerObject) + .filter(it => it.component === DollarDollarTransformer.callExpressionName(node)) + + return singleArgument.properties + .filter(ts.isPropertyAssignment) + .map(it => { + if (!ts.isIdentifier(it.name)) { + return undefined + } + return { + name: ts.idText(it.name), + initializer: it.initializer + } + }) + .filter(isDefined) + .map(initialization => { + const viablePass = viablePasses + .find(it => it.parameter === initialization.name) + if (viablePass === undefined) { + return undefined + } + if (!ts.isCallExpression(initialization.initializer)) { + return undefined + } + if (!DollarDollarTransformer.isDollarDollar(initialization.initializer)) { + return undefined + } + return { + parameter: initialization.name, + type: viablePass.type, + initializer: initialization.initializer.arguments[0] + } + }) + .filter(isDefined) + } + + static componentMethodCallInitializations(node: ts.CallExpression, collected: Initialization[] = []): Initialization[] { + if (!ts.isPropertyAccessExpression(node.expression)) { + return [] + } + if (ts.isEtsComponentExpression(node.expression.expression)) { + return collected + } + if (!ts.isCallExpression(node.expression.expression)) { + return [] + } + return this.componentMethodCallInitializations( + node.expression.expression, + collected.concat( + DollarDollarTransformer.callInitializations(node) + ) + ) + } + + static callInitializations(node: ts.CallExpression): Initialization[] { + if (!ts.isIdentifier(node.expression)) { + return [] + } + const firstArgument = node.arguments[0] + if (firstArgument === undefined) { + return [] + } + if (!ts.isCallExpression(firstArgument)) { + return [] + } + if (!DollarDollarTransformer.isDollarDollar(firstArgument)) { + return [] + } + const method = ts.idText(node.expression) + return dollarDollarViablePasses + .filter(isComponentMethodCall) // TODO: bindSheet too + .filter(it => it.method === method) + .map(it => ({ + parameter: it.parameter, + type: it.type, + initializer: firstArgument.arguments[0] + })) + } +} diff --git a/arkoala/ets-plugin/src/DollarTransformer.ts b/arkoala/ets-plugin/src/DollarTransformer.ts index 12a3dfe998a43deec035f78008c520a102133f9c..f2c1ce2222b97dc707f1406884676e70a3e29b3d 100644 --- a/arkoala/ets-plugin/src/DollarTransformer.ts +++ b/arkoala/ets-plugin/src/DollarTransformer.ts @@ -18,7 +18,6 @@ import { AbstractVisitor } from "./AbstractVisitor"; import { NameTable } from "./utils"; import { Importer } from "./Importer"; - export interface ApplicationInfo { bundleName: string, moduleName: string @@ -44,7 +43,7 @@ export class DollarTransformer extends AbstractVisitor { if (!name.startsWith("$")) return false const fieldName = name.substring(1) // TODO: is it correct? - // The white list has a preference over the fields. + // The white list has a preference over the fields. if (this.whiteList.includes(name)) return false if (!this.currentStruct) return false if (this.currentStruct.members.find(it => ( @@ -74,12 +73,12 @@ export class DollarTransformer extends AbstractVisitor { const name = ts.idText(node.expression as ts.Identifier).replace('$', '_') const args = node.arguments.slice() - + args.unshift( - ts.factory.createStringLiteral(this.applicationInfo?.bundleName ?? ""), + ts.factory.createStringLiteral(this.applicationInfo?.bundleName ?? ""), ts.factory.createStringLiteral(this.applicationInfo?.moduleName ?? "entry") ) - + return ts.factory.updateCallExpression( node, ts.factory.createIdentifier(this.importer.withAdaptorImport(name)), @@ -90,13 +89,11 @@ export class DollarTransformer extends AbstractVisitor { } visitor(node: ts.Node): ts.Node { - if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) { if (this.isDollarCallExpression(node)) { return this.transformDollarCallExpression(node) } } - if (ts.isStruct(node)) { this.currentStruct = node const transformed = this.visitEachChild(node) diff --git a/arkoala/ets-plugin/src/arkui-knowledge-base/dollar-dollar-viable-passes.ts b/arkoala/ets-plugin/src/arkui-knowledge-base/dollar-dollar-viable-passes.ts new file mode 100644 index 0000000000000000000000000000000000000000..f7857f0eb273e17de0686c6843c6fd6e397ce0b6 --- /dev/null +++ b/arkoala/ets-plugin/src/arkui-knowledge-base/dollar-dollar-viable-passes.ts @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 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 ts from "@koalaui/ets-tsc" + +abstract class PassType { + protected constructor( + public parameter: string, + public type: ts.TypeNode + ) {} +} + +class InitializerObject extends PassType { + constructor( + parameter: string, + type: ts.TypeNode, + public readonly component: string, + ) { + super(parameter, type) + } +} + +class ComponentMethodCall extends PassType { + constructor( + parameter: string, + type: ts.TypeNode, + public readonly component: string, + public readonly method: string, + ) { + super(parameter, type) + } +} + +class MethodCall extends PassType { + constructor( + parameter: string, + type: ts.TypeNode, + public readonly method: string, + ) { + super(parameter, type) + } +} + +export function isInitializerObject(value: PassType): value is InitializerObject { + return value instanceof InitializerObject +} + +export function isComponentMethodCall(value: PassType): value is ComponentMethodCall { + return value instanceof ComponentMethodCall +} + +export const dollarDollarViablePasses: PassType[] = [ + new ComponentMethodCall(`value`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), `Checkbox`, `select`), + new ComponentMethodCall(`value`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), `CheckboxGroup`, `selectAll`), + new InitializerObject(`selected`, ts.factory.createTypeReferenceNode(`Date`), `DatePicker`), + new InitializerObject(`selected`, ts.factory.createTypeReferenceNode(`Date`), `TimePicker`), + new InitializerObject(`isOn`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), `Toggle`), + new ComponentMethodCall(`value`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), `MenuItem`, `selected`), + new ComponentMethodCall(`value`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), `Select`, `value`), + new ComponentMethodCall(`value`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword), `Select`, `selected`), + new InitializerObject(`value`, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), `Search`), + // new ComponentMethodCall(`value`, `Panel`, `mode`), + // new InitializerObject(`value`, `Search`), + // TODO +] diff --git a/arkoala/ets-plugin/src/utils.ts b/arkoala/ets-plugin/src/utils.ts index 3dd8183078f03a125f6c91a077a303959e9fd702..d1124bb237d2306ed72e6eaa8f13536f1c1b5be4 100644 --- a/arkoala/ets-plugin/src/utils.ts +++ b/arkoala/ets-plugin/src/utils.ts @@ -46,6 +46,7 @@ export const ArkCommonMethodComponent = "ArkCommonMethodComponent" export const T_TypeParameter = "T" export const CommonInstance = "CommonInstance" export const Instance = "Instance" +export const DollarDollar = "$$" export enum SyncedPropertyConstructor { propState = "propState", diff --git a/arkoala/ets-plugin/test/ets/dollar-dollar/components.ets b/arkoala/ets-plugin/test/ets/dollar-dollar/components.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e7cfa06f361497892ed462c24f66437fbff603f --- /dev/null +++ b/arkoala/ets-plugin/test/ets/dollar-dollar/components.ets @@ -0,0 +1,65 @@ +@Entry +@Component +struct DollarDollar { + @State n: number = 0.5 + @State s: string = "0.5" + @State b: boolean = true + @State d: Date = new Date('2021-08-08') + @State m: PanelMode = PanelMode.Mini + @State l: ListItemStyle = ListItemStyle.NONE + + build() { + Column() { + Slider({ value: this.n }) + Toggle({ type: ToggleType.Switch, isOn: $$(this.b) }) + Stepper({ index: this.n }) + Checkbox() + .select($$(this.b)) + CheckboxGroup() + .selectAll($$(this.b)) + DatePicker({ selected: $$(this.d) }) + TimePicker({ selected: $$(this.d) }) + MenuItem() + .selected($$(this.b)) + Panel(false) + .mode($$(this.m)) + Radio({group: "", value: ""}) + .checked($$(this.b)) + Search({ value: $$(this.s) }) + SideBarContainer(SideBarContainerType.Embed) + .showSideBar($$(this.b)) + Swiper() + .index($$(this.n)) + Tabs({ index: $$(this.n) }) + TextInput({ text: $$(this.s) }) + TextArea({ text: $$(this.s) }) + TextInput({ text: $$(this.s) }) + Toggle({ type: ToggleType.Checkbox, isOn: $$(this.b) }) + AlphabetIndexer({arrayValue: [], selected: $$(this.n) }) + Refresh({ refreshing: $$(this.b) }) + TextPicker({ range: [], value: $$(this.s), selected: $$(this.n) }) + Select([]) + .value($$(this.s)) + .selected($$(this.n)) + List() { + ListItemGroup() { + ListItem({ style: this.l }) + .selected($$(this.b)) + } + } + Grid() { + GridItem({}) + .selected($$(this.b)) + } + + Button() + .bindSheet($$(this.b), builder) + .bindContentCover($$(this.b), builder) + } + } +} + +@Builder +function builder() { + Text() +} \ No newline at end of file diff --git a/arkoala/ets-plugin/test/golden/arkoala/ets/__router_initialization.ts b/arkoala/ets-plugin/test/golden/arkoala/ets/__router_initialization.ts index acedfbdd34f252a618f4e43a5939809cc4d476e1..b9a4cbf7caa258b79bfa11781c97e0ae93d7c618 100644 --- a/arkoala/ets-plugin/test/golden/arkoala/ets/__router_initialization.ts +++ b/arkoala/ets-plugin/test/golden/arkoala/ets/__router_initialization.ts @@ -2,11 +2,13 @@ import { EntryExample as Entry0 } from "./Rewrite" import { LocalStorageLinkExample as Entry1 } from "./Rewrite2" import { LocalStoragePropExample as Entry2 } from "./Rewrite3" -import { Index as Entry3 } from "./dollar-functions/dollar-functions" +import { DollarDollar as Entry3 } from "./dollar-dollar/components" +import { Index as Entry4 } from "./dollar-functions/dollar-functions" export function registerRoutes() { const __forceEntry0Use = Entry0 const __forceEntry1Use = Entry1 const __forceEntry2Use = Entry2 const __forceEntry3Use = Entry3 + const __forceEntry4Use = Entry4 } diff --git a/arkoala/ets-plugin/test/golden/arkoala/ets/dollar-dollar/components.ts b/arkoala/ets-plugin/test/golden/arkoala/ets/dollar-dollar/components.ts new file mode 100644 index 0000000000000000000000000000000000000000..7071e10c593f419abea91924acd3ebf69647a95f --- /dev/null +++ b/arkoala/ets-plugin/test/golden/arkoala/ets/dollar-dollar/components.ts @@ -0,0 +1,169 @@ +import { $$, ArkAlphabetIndexer, ArkButton, ArkButtonComponent, ArkCheckbox, ArkCheckboxComponent, ArkCheckboxGroup, ArkCheckboxGroupComponent, ArkColumn, ArkCommonMethodComponent, ArkDatePicker, ArkDatePickerComponent, ArkGrid, ArkGridItem, ArkGridItemComponent, ArkList, ArkListItem, ArkListItemComponent, ArkListItemGroup, ArkMenuItem, ArkMenuItemComponent, ArkPageTransitionEnterComponent, ArkPageTransitionExitComponent, ArkPanel, ArkPanelComponent, ArkRadio, ArkRadioComponent, ArkRefresh, ArkSearch, ArkSearchComponent, ArkSelect, ArkSelectComponent, ArkSideBarContainer, ArkSideBarContainerComponent, ArkSlider, ArkStepper, ArkStructBase, ArkSwiper, ArkSwiperComponent, ArkTabs, ArkText, ArkTextArea, ArkTextInput, ArkTextPicker, ArkTimePicker, ArkTimePickerComponent, ArkToggle, ArkToggleComponent, ListItemStyle, LocalStorage, MutableState, PanelMode, SideBarContainerType, ToggleType, _$, contextLocalStateOf, observableProxy, stateOf } from "@koalaui/arkoala-arkui"; +import { registerArkuiEntry } from "@koalaui/arkoala-arkui/ohos.router"; +class ArkDollarDollarComponent extends ArkStructBase { + private _entry_local_storage_ = new LocalStorage(); + __initializeStruct(/**/ + /** @memo */ + content?: () => void, initializers?: DollarDollarOptions): void { + this.__backing_n = stateOf(initializers?.n ?? (0.5), this); + this.__backing_s = stateOf(initializers?.s ?? ("0.5"), this); + this.__backing_b = stateOf(initializers?.b ?? (true), this); + this.__backing_d = stateOf(initializers?.d ?? (new Date('2021-08-08')), this); + this.__backing_m = stateOf(initializers?.m ?? (PanelMode.Mini), this); + this.__backing_l = stateOf(initializers?.l ?? (ListItemStyle.NONE), this); + } + private __backing_n?: MutableState; + private get n(): number { + return this.__backing_n!.value; + } + private set n(value: number) { + this.__backing_n!.value = observableProxy(value); + } + private __backing_s?: MutableState; + private get s(): string { + return this.__backing_s!.value; + } + private set s(value: string) { + this.__backing_s!.value = observableProxy(value); + } + private __backing_b?: MutableState; + private get b(): boolean { + return this.__backing_b!.value; + } + private set b(value: boolean) { + this.__backing_b!.value = observableProxy(value); + } + private __backing_d?: MutableState; + private get d(): Date { + return this.__backing_d!.value; + } + private set d(value: Date) { + this.__backing_d!.value = observableProxy(value); + } + private __backing_m?: MutableState; + private get m(): PanelMode { + return this.__backing_m!.value; + } + private set m(value: PanelMode) { + this.__backing_m!.value = observableProxy(value); + } + private __backing_l?: MutableState; + private get l(): ListItemStyle { + return this.__backing_l!.value; + } + private set l(value: ListItemStyle) { + this.__backing_l!.value = observableProxy(value); + } + /** @memo */ + __build(/**/ + /** @memo */ + __builder: ((__instance: ArkCommonMethodComponent) => void) | undefined, /**/ + /** @memo */ + content?: () => void, initializers?: DollarDollarOptions) { + ArkColumn(__builder, () => { + ArkSlider(undefined, undefined, { value: this.n }); + ArkToggle((__instance: ArkToggleComponent) => { + __instance.__OnChanged_isOn((isOn: boolean): void => { this.b = isOn; }); + }, undefined, { type: ToggleType.Switch, isOn: _$("com.application.example", "entry", this.b) }); + ArkStepper(undefined, undefined, { index: this.n }); + ArkCheckbox((__instance: ArkCheckboxComponent) => { + __instance.select(_$("com.application.example", "entry", this.b)); + }, undefined); + ArkCheckboxGroup((__instance: ArkCheckboxGroupComponent) => { + __instance.selectAll(_$("com.application.example", "entry", this.b)); + }, undefined); + ArkDatePicker((__instance: ArkDatePickerComponent) => { + __instance.__OnChanged_selected((selected: Date): void => { this.d = selected; }); + }, undefined, { selected: _$("com.application.example", "entry", this.d) }); + ArkTimePicker((__instance: ArkTimePickerComponent) => { + __instance.__OnChanged_selected((selected: Date): void => { this.d = selected; }); + }, undefined, { selected: _$("com.application.example", "entry", this.d) }); + ArkMenuItem((__instance: ArkMenuItemComponent) => { + __instance.selected(_$("com.application.example", "entry", this.b)); + }, undefined); + ArkPanel((__instance: ArkPanelComponent) => { + __instance.mode(_$("com.application.example", "entry", this.m)); + }, undefined, false); + ArkRadio((__instance: ArkRadioComponent) => { + __instance.checked(_$("com.application.example", "entry", this.b)); + }, undefined, { group: "", value: "" }); + ArkSearch((__instance: ArkSearchComponent) => { + __instance.__OnChanged_value((value: string): void => { this.s = value; }); + }, undefined, { value: _$("com.application.example", "entry", this.s) }); + ArkSideBarContainer((__instance: ArkSideBarContainerComponent) => { + __instance.showSideBar(_$("com.application.example", "entry", this.b)); + }, undefined, SideBarContainerType.Embed); + ArkSwiper((__instance: ArkSwiperComponent) => { + __instance.index(_$("com.application.example", "entry", this.n)); + }, undefined); + ArkTabs(undefined, undefined, { index: _$("com.application.example", "entry", this.n) }); + ArkTextInput(undefined, undefined, { text: _$("com.application.example", "entry", this.s) }); + ArkTextArea(undefined, undefined, { text: _$("com.application.example", "entry", this.s) }); + ArkTextInput(undefined, undefined, { text: _$("com.application.example", "entry", this.s) }); + ArkToggle((__instance: ArkToggleComponent) => { + __instance.__OnChanged_isOn((isOn: boolean): void => { this.b = isOn; }); + }, undefined, { type: ToggleType.Checkbox, isOn: _$("com.application.example", "entry", this.b) }); + ArkAlphabetIndexer(undefined, undefined, { arrayValue: [], selected: _$("com.application.example", "entry", this.n) }); + ArkRefresh(undefined, undefined, { refreshing: _$("com.application.example", "entry", this.b) }); + ArkTextPicker(undefined, undefined, { range: [], value: _$("com.application.example", "entry", this.s), selected: _$("com.application.example", "entry", this.n) }); + ArkSelect((__instance: ArkSelectComponent) => { + __instance.value(_$("com.application.example", "entry", this.s)) + .selected(_$("com.application.example", "entry", this.n)); + }, undefined, []); + ArkList(undefined, () => { + ArkListItemGroup(undefined, () => { + ArkListItem((__instance: ArkListItemComponent) => { + __instance.selected(_$("com.application.example", "entry", this.b)); + }, undefined, { style: this.l }); + }); + }); + ArkGrid(undefined, () => { + ArkGridItem((__instance: ArkGridItemComponent) => { + __instance.selected(_$("com.application.example", "entry", this.b)); + }, undefined, {}); + }); + ArkButton((__instance: ArkButtonComponent) => { + __instance.bindSheet(_$("com.application.example", "entry", this.b), builder) + .bindContentCover(_$("com.application.example", "entry", this.b), builder); + }, undefined); + }); + } +} +/** @memo */ +function builder() { + ArkText(undefined, undefined); +} +/** @memo */ +export function DollarDollar(/**/ +/** @memo */ +style?: (__instance: ArkCommonMethodComponent) => void, /**/ +/** @memo */ +content?: () => void, initializers?: DollarDollarOptions): void { + contextLocalStateOf("contextLocalMapOfRadioGroups", () => new Map()); + contextLocalStateOf("contextLocalMapOfCheckboxGroups", () => new Map()); + const updatedInitializers: DollarDollarOptions = { + __backing_n: initializers?.__backing_n, + __backing_s: initializers?.__backing_s, + __backing_b: initializers?.__backing_b, + __backing_d: initializers?.__backing_d, + __backing_m: initializers?.__backing_m, + __backing_l: initializers?.__backing_l + }; + ArkDollarDollarComponent._instantiate(style, () => new ArkDollarDollarComponent, content, updatedInitializers); +} +export interface DollarDollarOptions { + __backing_n?: MutableState; + n?: number; + __backing_s?: MutableState; + s?: string; + __backing_b?: MutableState; + b?: boolean; + __backing_d?: MutableState; + d?: Date; + __backing_m?: MutableState; + m?: PanelMode; + __backing_l?: MutableState; + l?: ListItemStyle; +} +registerArkuiEntry(DollarDollar, "dollar-dollar/components"); +export const __Entry = DollarDollar; diff --git a/arkoala/ets-plugin/test/golden/arkts/ets/dollar-dollar/components.ts b/arkoala/ets-plugin/test/golden/arkts/ets/dollar-dollar/components.ts new file mode 100644 index 0000000000000000000000000000000000000000..2756437eb58e70dc60f06fc9eb77d8be115b9780 --- /dev/null +++ b/arkoala/ets-plugin/test/golden/arkts/ets/dollar-dollar/components.ts @@ -0,0 +1,169 @@ +import { $$, AlphabetIndexerOptions, ArkAlphabetIndexer, ArkButton, ArkButtonComponent, ArkCheckbox, ArkCheckboxComponent, ArkCheckboxGroup, ArkCheckboxGroupComponent, ArkColumn, ArkCommonMethodComponent, ArkDatePicker, ArkDatePickerComponent, ArkGrid, ArkGridItem, ArkGridItemComponent, ArkList, ArkListItem, ArkListItemComponent, ArkListItemGroup, ArkMenuItem, ArkMenuItemComponent, ArkPageTransitionEnterComponent, ArkPageTransitionExitComponent, ArkPanel, ArkPanelComponent, ArkRadio, ArkRadioComponent, ArkRefresh, ArkSearch, ArkSearchComponent, ArkSelect, ArkSelectComponent, ArkSideBarContainer, ArkSideBarContainerComponent, ArkSlider, ArkStepper, ArkStructBase, ArkSwiper, ArkSwiperComponent, ArkTabs, ArkText, ArkTextArea, ArkTextInput, ArkTextPicker, ArkTimePicker, ArkTimePickerComponent, ArkToggle, ArkToggleComponent, DatePickerOptions, GridItemOptions, ListItemOptions, ListItemStyle, PanelMode, RadioOptions, RefreshOptions, SearchOptions, SideBarContainerType, SliderOptions, StepperOptions, TabsOptions, TextAreaOptions, TextInputOptions, TextPickerOptions, TimePickerOptions, ToggleOptions, ToggleType, _$, contextLocalStateOf, stateOf } from "@koalaui/arkts-arkui"; +import { MutableState } from "@koalaui/runtime"; +import { LocalStorage } from "@koalaui/arkui-common"; +import { observableProxy } from "@koalaui/common"; +class ArkDollarDollarComponent extends ArkStructBase { + private _entry_local_storage_ = new LocalStorage(); + __initializeStruct(/**/ + /** @memo */ + content?: () => void, initializers?: DollarDollarOptions): void { + this.__backing_n = stateOf(initializers?.n ?? (0.5), this); + this.__backing_s = stateOf(initializers?.s ?? ("0.5"), this); + this.__backing_b = stateOf(initializers?.b ?? (true), this); + this.__backing_d = stateOf(initializers?.d ?? (new Date('2021-08-08')), this); + this.__backing_m = stateOf(initializers?.m ?? (PanelMode.Mini), this); + this.__backing_l = stateOf(initializers?.l ?? (ListItemStyle.NONE), this); + } + private __backing_n?: MutableState; + private get n(): number { + return this.__backing_n!.value; + } + private set n(value: number) { + this.__backing_n!.value = observableProxy(value); + } + private __backing_s?: MutableState; + private get s(): string { + return this.__backing_s!.value; + } + private set s(value: string) { + this.__backing_s!.value = observableProxy(value); + } + private __backing_b?: MutableState; + private get b(): boolean { + return this.__backing_b!.value; + } + private set b(value: boolean) { + this.__backing_b!.value = observableProxy(value); + } + private __backing_d?: MutableState; + private get d(): Date { + return this.__backing_d!.value; + } + private set d(value: Date) { + this.__backing_d!.value = observableProxy(value); + } + private __backing_m?: MutableState; + private get m(): PanelMode { + return this.__backing_m!.value; + } + private set m(value: PanelMode) { + this.__backing_m!.value = observableProxy(value); + } + private __backing_l?: MutableState; + private get l(): ListItemStyle { + return this.__backing_l!.value; + } + private set l(value: ListItemStyle) { + this.__backing_l!.value = observableProxy(value); + } + /** @memo */ + __build(/**/ + /** @memo */ + __builder: ((__instance: ArkCommonMethodComponent) => void) | undefined, /**/ + /** @memo */ + content?: () => void, initializers?: DollarDollarOptions) { + ArkColumn(__builder, () => { + ArkSlider(undefined, undefined, { value: this.n } as SliderOptions); + ArkToggle((__instance: ArkToggleComponent) => { + __instance.__OnChanged_isOn((isOn: boolean): void => { this.b = isOn; }); + }, undefined, { type: ToggleType.Switch, isOn: _$("com.application.example", "entry", this.b) } as ToggleOptions); + ArkStepper(undefined, undefined, { index: this.n } as StepperOptions); + ArkCheckbox((__instance: ArkCheckboxComponent) => { + __instance.select(_$("com.application.example", "entry", this.b)); + }, undefined); + ArkCheckboxGroup((__instance: ArkCheckboxGroupComponent) => { + __instance.selectAll(_$("com.application.example", "entry", this.b)); + }, undefined); + ArkDatePicker((__instance: ArkDatePickerComponent) => { + __instance.__OnChanged_selected((selected: Date): void => { this.d = selected; }); + }, undefined, { selected: _$("com.application.example", "entry", this.d) } as DatePickerOptions); + ArkTimePicker((__instance: ArkTimePickerComponent) => { + __instance.__OnChanged_selected((selected: Date): void => { this.d = selected; }); + }, undefined, { selected: _$("com.application.example", "entry", this.d) } as TimePickerOptions); + ArkMenuItem((__instance: ArkMenuItemComponent) => { + __instance.selected(_$("com.application.example", "entry", this.b)); + }, undefined); + ArkPanel((__instance: ArkPanelComponent) => { + __instance.mode(_$("com.application.example", "entry", this.m)); + }, undefined, false); + ArkRadio((__instance: ArkRadioComponent) => { + __instance.checked(_$("com.application.example", "entry", this.b)); + }, undefined, { group: "", value: "" } as RadioOptions); + ArkSearch((__instance: ArkSearchComponent) => { + __instance.__OnChanged_value((value: string): void => { this.s = value; }); + }, undefined, { value: _$("com.application.example", "entry", this.s) } as SearchOptions); + ArkSideBarContainer((__instance: ArkSideBarContainerComponent) => { + __instance.showSideBar(_$("com.application.example", "entry", this.b)); + }, undefined, SideBarContainerType.Embed); + ArkSwiper((__instance: ArkSwiperComponent) => { + __instance.index(_$("com.application.example", "entry", this.n)); + }, undefined); + ArkTabs(undefined, undefined, { index: _$("com.application.example", "entry", this.n) } as TabsOptions); + ArkTextInput(undefined, undefined, { text: _$("com.application.example", "entry", this.s) } as TextInputOptions); + ArkTextArea(undefined, undefined, { text: _$("com.application.example", "entry", this.s) } as TextAreaOptions); + ArkTextInput(undefined, undefined, { text: _$("com.application.example", "entry", this.s) } as TextInputOptions); + ArkToggle((__instance: ArkToggleComponent) => { + __instance.__OnChanged_isOn((isOn: boolean): void => { this.b = isOn; }); + }, undefined, { type: ToggleType.Checkbox, isOn: _$("com.application.example", "entry", this.b) } as ToggleOptions); + ArkAlphabetIndexer(undefined, undefined, { arrayValue: [], selected: _$("com.application.example", "entry", this.n) } as AlphabetIndexerOptions); + ArkRefresh(undefined, undefined, { refreshing: _$("com.application.example", "entry", this.b) } as RefreshOptions); + ArkTextPicker(undefined, undefined, { range: [], value: _$("com.application.example", "entry", this.s), selected: _$("com.application.example", "entry", this.n) } as TextPickerOptions); + ArkSelect((__instance: ArkSelectComponent) => { + __instance.value(_$("com.application.example", "entry", this.s)) + .selected(_$("com.application.example", "entry", this.n)); + }, undefined, []); + ArkList(undefined, () => { + ArkListItemGroup(undefined, () => { + ArkListItem((__instance: ArkListItemComponent) => { + __instance.selected(_$("com.application.example", "entry", this.b)); + }, undefined, { style: this.l } as ListItemOptions); + }); + }); + ArkGrid(undefined, () => { + ArkGridItem((__instance: ArkGridItemComponent) => { + __instance.selected(_$("com.application.example", "entry", this.b)); + }, undefined, {} as GridItemOptions); + }); + ArkButton((__instance: ArkButtonComponent) => { + __instance.bindSheet(_$("com.application.example", "entry", this.b), builder) + .bindContentCover(_$("com.application.example", "entry", this.b), builder); + }, undefined); + }); + } +} +/** @memo */ +function builder() { + ArkText(undefined, undefined); +} +/** @memo */ +export function DollarDollar(/**/ +/** @memo */ +style?: (__instance: ArkCommonMethodComponent) => void, /**/ +/** @memo */ +content?: () => void, initializers?: DollarDollarOptions): void { + contextLocalStateOf("contextLocalMapOfRadioGroups", () => new Map()); + contextLocalStateOf("contextLocalMapOfCheckboxGroups", () => new Map()); + const updatedInitializers: DollarDollarOptions = { + __backing_n: initializers?.__backing_n, + __backing_s: initializers?.__backing_s, + __backing_b: initializers?.__backing_b, + __backing_d: initializers?.__backing_d, + __backing_m: initializers?.__backing_m, + __backing_l: initializers?.__backing_l + }; + ArkDollarDollarComponent._instantiate(style, () => new ArkDollarDollarComponent, content, updatedInitializers); +} +export interface DollarDollarOptions { + __backing_n?: MutableState; + n?: number; + __backing_s?: MutableState; + s?: string; + __backing_b?: MutableState; + b?: boolean; + __backing_d?: MutableState; + d?: Date; + __backing_m?: MutableState; + m?: PanelMode; + __backing_l?: MutableState; + l?: ListItemStyle; +} diff --git a/arkoala/ets-plugin/test/golden/koala/ets/__router_initialization.ts b/arkoala/ets-plugin/test/golden/koala/ets/__router_initialization.ts index acedfbdd34f252a618f4e43a5939809cc4d476e1..b9a4cbf7caa258b79bfa11781c97e0ae93d7c618 100644 --- a/arkoala/ets-plugin/test/golden/koala/ets/__router_initialization.ts +++ b/arkoala/ets-plugin/test/golden/koala/ets/__router_initialization.ts @@ -2,11 +2,13 @@ import { EntryExample as Entry0 } from "./Rewrite" import { LocalStorageLinkExample as Entry1 } from "./Rewrite2" import { LocalStoragePropExample as Entry2 } from "./Rewrite3" -import { Index as Entry3 } from "./dollar-functions/dollar-functions" +import { DollarDollar as Entry3 } from "./dollar-dollar/components" +import { Index as Entry4 } from "./dollar-functions/dollar-functions" export function registerRoutes() { const __forceEntry0Use = Entry0 const __forceEntry1Use = Entry1 const __forceEntry2Use = Entry2 const __forceEntry3Use = Entry3 + const __forceEntry4Use = Entry4 } diff --git a/arkoala/ets-plugin/test/golden/koala/ets/dollar-dollar/components.ts b/arkoala/ets-plugin/test/golden/koala/ets/dollar-dollar/components.ts new file mode 100644 index 0000000000000000000000000000000000000000..db935bf50533468bb072ec004507c3cdca7fec5c --- /dev/null +++ b/arkoala/ets-plugin/test/golden/koala/ets/dollar-dollar/components.ts @@ -0,0 +1,171 @@ +import { $$, $r, $rawfile, AppStorage, ArkAlphabetIndexer, ArkButton, ArkButtonComponent, ArkCheckbox, ArkCheckboxComponent, ArkCheckboxGroup, ArkCheckboxGroupComponent, ArkColumn, ArkCommonMethodComponent, ArkDatePicker, ArkDatePickerComponent, ArkGrid, ArkGridItem, ArkGridItemComponent, ArkList, ArkListItem, ArkListItemComponent, ArkListItemGroup, ArkMenuItem, ArkMenuItemComponent, ArkPageTransitionEnterComponent, ArkPageTransitionExitComponent, ArkPanel, ArkPanelComponent, ArkRadio, ArkRadioComponent, ArkRefresh, ArkSearch, ArkSearchComponent, ArkSelect, ArkSelectComponent, ArkSideBarContainer, ArkSideBarContainerComponent, ArkSlider, ArkStepper, ArkStructBase, ArkSwiper, ArkSwiperComponent, ArkTabs, ArkText, ArkTextArea, ArkTextInput, ArkTextPicker, ArkTimePicker, ArkTimePickerComponent, ArkToggle, ArkToggleComponent, CanvasRenderingContext2D, CustomDialogController, DataChangeListener, Environment, ForEach, GestureGroup, IDataSource, ListItemStyle, LocalStorage, LongPressGesture, PanGesture, PanGestureOptions, PanelMode, PersistentStorage, PinchGesture, RenderingContextSettings, RotationGesture, Scroller, SideBarContainerType, SubscribedAbstractProperty, SwipeGesture, SwiperController, TabsController, TapGesture, TextAreaController, ToggleType, VideoController, _$, animateTo, contextLocalStateOf, fp2px, getContext, getInspectorByKey, lpx2px, px2fp, px2lpx, px2vp, stateOf, vp2px } from "@koalaui/arkui"; +import { MutableState } from "@koalaui/runtime"; +import { registerArkuiEntry } from "@koalaui/arkui/ohos.router"; +import { observableProxy } from "@koalaui/common"; +class ArkDollarDollarComponent extends ArkStructBase { + private _entry_local_storage_ = new LocalStorage(); + __initializeStruct(/**/ + /** @memo */ + content?: () => void, initializers?: DollarDollarOptions): void { + this.__backing_n = stateOf(initializers?.n ?? (0.5), this); + this.__backing_s = stateOf(initializers?.s ?? ("0.5"), this); + this.__backing_b = stateOf(initializers?.b ?? (true), this); + this.__backing_d = stateOf(initializers?.d ?? (new Date('2021-08-08')), this); + this.__backing_m = stateOf(initializers?.m ?? (PanelMode.Mini), this); + this.__backing_l = stateOf(initializers?.l ?? (ListItemStyle.NONE), this); + } + private __backing_n?: MutableState; + private get n(): number { + return this.__backing_n!.value; + } + private set n(value: number) { + this.__backing_n!.value = observableProxy(value); + } + private __backing_s?: MutableState; + private get s(): string { + return this.__backing_s!.value; + } + private set s(value: string) { + this.__backing_s!.value = observableProxy(value); + } + private __backing_b?: MutableState; + private get b(): boolean { + return this.__backing_b!.value; + } + private set b(value: boolean) { + this.__backing_b!.value = observableProxy(value); + } + private __backing_d?: MutableState; + private get d(): Date { + return this.__backing_d!.value; + } + private set d(value: Date) { + this.__backing_d!.value = observableProxy(value); + } + private __backing_m?: MutableState; + private get m(): PanelMode { + return this.__backing_m!.value; + } + private set m(value: PanelMode) { + this.__backing_m!.value = observableProxy(value); + } + private __backing_l?: MutableState; + private get l(): ListItemStyle { + return this.__backing_l!.value; + } + private set l(value: ListItemStyle) { + this.__backing_l!.value = observableProxy(value); + } + /** @memo */ + __build(/**/ + /** @memo */ + __builder: ((__instance: ArkCommonMethodComponent) => void) | undefined, /**/ + /** @memo */ + content?: () => void, initializers?: DollarDollarOptions) { + ArkColumn(__builder, () => { + ArkSlider(undefined, undefined, { value: this.n }); + ArkToggle((__instance: ArkToggleComponent) => { + __instance.__OnChanged_isOn((isOn: boolean): void => { this.b = isOn; }); + }, undefined, { type: ToggleType.Switch, isOn: _$("", "entry", this.b) }); + ArkStepper(undefined, undefined, { index: this.n }); + ArkCheckbox((__instance: ArkCheckboxComponent) => { + __instance.select(_$("", "entry", this.b)); + }, undefined); + ArkCheckboxGroup((__instance: ArkCheckboxGroupComponent) => { + __instance.selectAll(_$("", "entry", this.b)); + }, undefined); + ArkDatePicker((__instance: ArkDatePickerComponent) => { + __instance.__OnChanged_selected((selected: Date): void => { this.d = selected; }); + }, undefined, { selected: _$("", "entry", this.d) }); + ArkTimePicker((__instance: ArkTimePickerComponent) => { + __instance.__OnChanged_selected((selected: Date): void => { this.d = selected; }); + }, undefined, { selected: _$("", "entry", this.d) }); + ArkMenuItem((__instance: ArkMenuItemComponent) => { + __instance.selected(_$("", "entry", this.b)); + }, undefined); + ArkPanel((__instance: ArkPanelComponent) => { + __instance.mode(_$("", "entry", this.m)); + }, undefined, false); + ArkRadio((__instance: ArkRadioComponent) => { + __instance.checked(_$("", "entry", this.b)); + }, undefined, { group: "", value: "" }); + ArkSearch((__instance: ArkSearchComponent) => { + __instance.__OnChanged_value((value: string): void => { this.s = value; }); + }, undefined, { value: _$("", "entry", this.s) }); + ArkSideBarContainer((__instance: ArkSideBarContainerComponent) => { + __instance.showSideBar(_$("", "entry", this.b)); + }, undefined, SideBarContainerType.Embed); + ArkSwiper((__instance: ArkSwiperComponent) => { + __instance.index(_$("", "entry", this.n)); + }, undefined); + ArkTabs(undefined, undefined, { index: _$("", "entry", this.n) }); + ArkTextInput(undefined, undefined, { text: _$("", "entry", this.s) }); + ArkTextArea(undefined, undefined, { text: _$("", "entry", this.s) }); + ArkTextInput(undefined, undefined, { text: _$("", "entry", this.s) }); + ArkToggle((__instance: ArkToggleComponent) => { + __instance.__OnChanged_isOn((isOn: boolean): void => { this.b = isOn; }); + }, undefined, { type: ToggleType.Checkbox, isOn: _$("", "entry", this.b) }); + ArkAlphabetIndexer(undefined, undefined, { arrayValue: [], selected: _$("", "entry", this.n) }); + ArkRefresh(undefined, undefined, { refreshing: _$("", "entry", this.b) }); + ArkTextPicker(undefined, undefined, { range: [], value: _$("", "entry", this.s), selected: _$("", "entry", this.n) }); + ArkSelect((__instance: ArkSelectComponent) => { + __instance.value(_$("", "entry", this.s)) + .selected(_$("", "entry", this.n)); + }, undefined, []); + ArkList(undefined, () => { + ArkListItemGroup(undefined, () => { + ArkListItem((__instance: ArkListItemComponent) => { + __instance.selected(_$("", "entry", this.b)); + }, undefined, { style: this.l }); + }); + }); + ArkGrid(undefined, () => { + ArkGridItem((__instance: ArkGridItemComponent) => { + __instance.selected(_$("", "entry", this.b)); + }, undefined, {}); + }); + ArkButton((__instance: ArkButtonComponent) => { + __instance.bindSheet(_$("", "entry", this.b), builder) + .bindContentCover(_$("", "entry", this.b), builder); + }, undefined); + }); + } +} +/** @memo */ +function builder() { + ArkText(undefined, undefined); +} +/** @memo */ +export function DollarDollar(/**/ +/** @memo */ +style?: (__instance: ArkCommonMethodComponent) => void, /**/ +/** @memo */ +content?: () => void, initializers?: DollarDollarOptions): void { + contextLocalStateOf("contextLocalMapOfRadioGroups", () => new Map()); + contextLocalStateOf("contextLocalMapOfCheckboxGroups", () => new Map()); + const updatedInitializers: DollarDollarOptions = { + __backing_n: initializers?.__backing_n, + __backing_s: initializers?.__backing_s, + __backing_b: initializers?.__backing_b, + __backing_d: initializers?.__backing_d, + __backing_m: initializers?.__backing_m, + __backing_l: initializers?.__backing_l + }; + ArkDollarDollarComponent._instantiate(style, () => new ArkDollarDollarComponent, content, updatedInitializers); +} +export interface DollarDollarOptions { + __backing_n?: MutableState; + n?: number; + __backing_s?: MutableState; + s?: string; + __backing_b?: MutableState; + b?: boolean; + __backing_d?: MutableState; + d?: Date; + __backing_m?: MutableState; + m?: PanelMode; + __backing_l?: MutableState; + l?: ListItemStyle; +} +registerArkuiEntry(DollarDollar, "dollar-dollar/components"); +export const __Entry = DollarDollar; diff --git a/arkoala/ets-plugin/test/rewrites.test.ts b/arkoala/ets-plugin/test/rewrites.test.ts index 7568987c1352a8febc5559c5be057cf6240637fd..42b6978a4b63fd6800f01376c92ac39ceeb3709a 100644 --- a/arkoala/ets-plugin/test/rewrites.test.ts +++ b/arkoala/ets-plugin/test/rewrites.test.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { assertGeneratedEqualsGolden } from "./utils" +import { assertGeneratedEqualsGolden, testFolder } from "./utils" suite("Basic rewrites of ArkUI syntactic features", () => { test("Basic rewrites", () => assertGeneratedEqualsGolden("Rewrite.ts")) @@ -39,6 +39,8 @@ suite("Basic rewrites of ArkUI syntactic features", () => { test("Trailing block user structs", () => assertGeneratedEqualsGolden("trailing-block.ts")) }) +testFolder("dollar-dollar") + suite("Arkts rewrites", () => { test("Rewrite.ets", () => assertGeneratedEqualsGolden("arkts/Rewrite.ts")) test("Rewrite2.ets", () => assertGeneratedEqualsGolden("arkts/Rewrite2.ts")) diff --git a/arkoala/ets-plugin/test/utils.ts b/arkoala/ets-plugin/test/utils.ts index a4da1e0c137414064bbd61dcab5e93e7fff2a4e4..aba4f32aa171fa825c3a1bd52e934203cca5f713 100644 --- a/arkoala/ets-plugin/test/utils.ts +++ b/arkoala/ets-plugin/test/utils.ts @@ -28,7 +28,8 @@ export function testFolder(folder: string) { test(file, () => { assertEqualFiles( path.resolve(golden, file), - path.resolve(current, file)) + path.resolve(current, file) + ) }) }) })