diff --git a/arkui-plugins/ui-plugins/interop/initstatevar.ts b/arkui-plugins/ui-plugins/interop/initstatevar.ts index 77846dadb0ad6323ea3d0d8393be1e006f682739..b2ac2cf6d7a0c6e3dc0209e3c05a1cb6bb6fe9da 100644 --- a/arkui-plugins/ui-plugins/interop/initstatevar.ts +++ b/arkui-plugins/ui-plugins/interop/initstatevar.ts @@ -18,7 +18,7 @@ import * as arkts from '@koalaui/libarkts'; import { BuilderMethodNames, InteroperAbilityNames } from './predefines'; import { annotation, backingField, isAnnotation } from '../../common/arkts-utils'; -import { stateProxy, getWrapValue, setPropertyESValue } from './utils'; +import { stateProxy, getWrapValue, setPropertyESValue, createEmptyESValue } from './utils'; import { hasDecorator } from '../property-translators/utils'; import { DecoratorNames } from '../../common/predefines'; @@ -147,6 +147,34 @@ export function processLink(keyName: string, value: arkts.Expression, type: arkt return result; } +function processObjectLiteral(target: arkts.ObjectExpression, curParam: string, result: arkts.Statement[]): void { + if (curParam !== InteroperAbilityNames.PARAM) { + const createParam = createEmptyESValue(curParam); + result.push(createParam); + } + target.properties.forEach((property, index) => { + const paramName = curParam + index; + const key = property.key; + const value = property.value; + if (arkts.isObjectExpression(value)) { + processObjectLiteral(value, paramName, result); + const setProperty = setPropertyESValue( + curParam, + key.name, + arkts.factory.createIdentifier(paramName) + ); + result.push(setProperty); + } else { + const setProperty = setPropertyESValue( + curParam, + key.name, + getWrapValue(value) + ); + result.push(setProperty); + } + }); +} + /** * * @param keyName @@ -155,12 +183,16 @@ export function processLink(keyName: string, value: arkts.Expression, type: arkt */ export function processNormal(keyName: string, value: arkts.AstNode): arkts.Statement[] { const result: arkts.Statement[] = []; - const setProperty = setPropertyESValue( - InteroperAbilityNames.PARAM, - keyName, - getWrapValue(value) - ); - result.push(setProperty); + if (arkts.isObjectExpression(value)) { + processObjectLiteral(value, InteroperAbilityNames.PARAM, result); + } else { + const setProperty = setPropertyESValue( + InteroperAbilityNames.PARAM, + keyName, + getWrapValue(value) + ); + result.push(setProperty); + } return result; }