diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 484f906..a17447f 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -81,11 +81,11 @@ export function processCustomComponent(node: ts.ExpressionStatement, newStatemen // @ts-ignore argumentsArray = node.expression.arguments[0].properties.slice(); argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => { - if (ts.isCallExpression(item.initializer)) { + if (isToChange(item, node.expression as ts.CallExpression)) { ischangeNode = true; - const PropertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( - item, item.name, changeNodeFromCallToArrow(item.initializer)); - argumentsArray.splice(index, 1, PropertyAssignmentNode); + const propertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( + item, item.name, changeNodeFromCallToArrow(item.initializer as ts.CallExpression)); + argumentsArray.splice(index, 1, propertyAssignmentNode); } }); if (ischangeNode) { @@ -105,6 +105,12 @@ function isHasChild(node: ts.CallExpression): boolean { node.arguments[0].properties && node.arguments[0].properties.length; } +function isToChange(item: ts.PropertyAssignment, node: ts.CallExpression): boolean { + const builderParamName: Set = builderParamObjectCollection.get(node.expression.getText()); + return item.initializer && ts.isCallExpression(item.initializer) && builderParamName && + builderParamName.has(item.name.getText()); +} + function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ArrowFunction { return ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), @@ -146,7 +152,7 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string if (isThisProperty(item, propertySet)) { validateStateManagement(item, name, log); if (isNonThisProperty(item, linkSet)) { - if (item.initializer && ts.isCallExpression(item.initializer)) { + if (isToChange(item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, item.name, changeNodeFromCallToArrow(item.initializer)); } diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index b0e117a..d21e640 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -14,9 +14,11 @@ */ exports.source = ` + @Component struct CustomContainer { header: string = ""; + menuInfo: () => any; footer: string = ""; @BuilderParam child: () => any; @@ -32,10 +34,10 @@ struct CustomContainer { @Entry @Component struct CustomContainerUser { - @Builder specificChild() { + @Builder specificChild(label:string) { Column() { Text("My content1") - Text("My content2") + Text(label) } } @@ -44,7 +46,8 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - child: this.specificChild + menuInfo: this.specificChild("menuInfo"), + child: this.specificChild("child") }) } } @@ -55,6 +58,7 @@ exports.expectResult = constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.header = ""; + this.menuInfo = undefined; this.footer = ""; this.updateWithValueParams(params); } @@ -62,6 +66,9 @@ exports.expectResult = if (params.header !== undefined) { this.header = params.header; } + if (params.menuInfo !== undefined) { + this.menuInfo = params.menuInfo; + } if (params.footer !== undefined) { this.footer = params.footer; } @@ -90,31 +97,37 @@ class CustomContainerUser extends View { aboutToBeDeleted() { SubscriberManager.Get().delete(this.id()); } - specificChild() { + specificChild(label) { Column.create(); Text.create("My content1"); Text.pop(); - Text.create("My content2"); + Text.create(label); Text.pop(); Column.pop(); } render() { Column.create(); - let earlierCreatedChild_2 = this.findChildById("2"); - if (earlierCreatedChild_2 == undefined) { - View.create(new CustomContainer("2", this, { + let earlierCreatedChild_3 = this.findChildById("3"); + if (earlierCreatedChild_3 == undefined) { + View.create(new CustomContainer("3", this, { header: "Header", footer: "Footer", - child: this.specificChild + menuInfo: this.specificChild("menuInfo"), + child: () => { + this.specificChild("child"); + } })); } else { - earlierCreatedChild_2.updateWithValueParams({ + earlierCreatedChild_3.updateWithValueParams({ header: "Header", footer: "Footer", - child: this.specificChild + menuInfo: this.specificChild("menuInfo"), + child: () => { + this.specificChild("child"); + } }); - View.create(earlierCreatedChild_2); + View.create(earlierCreatedChild_3); } Column.pop(); }