From 305f2bc37b6fe1d1a36dcc0fcfb93d7a179e7caa Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 09:48:03 +0800 Subject: [PATCH 1/4] puyajun@huawei.com fix bug builderParam Signed-off-by: puyajun Change-Id: I087d4c546406030679c79e984b964530618660ec --- compiler/src/process_custom_component.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 484f906..e17abb5 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -81,10 +81,10 @@ 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)); + item, item.name, changeNodeFromCallToArrow(item.initializer as ts.CallExpression)); argumentsArray.splice(index, 1, PropertyAssignmentNode); } }); @@ -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 = builderParamObjectCollection.get(node.expression.getText()); + return 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,8 @@ 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 (item.initializer && ts.isCallExpression(item.initializer) && isToChange( + item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, item.name, changeNodeFromCallToArrow(item.initializer)); } From 4425a67be69db849d2234c1c6c00cf7dd087c43c Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 10:04:01 +0800 Subject: [PATCH 2/4] puyajun@huawei.com fix builderParam bug Signed-off-by: puyajun Change-Id: I6d40cbc496a46523553ef76cf1a74728f69c35f9 --- compiler/test/ut/builder/builderParam.ts | 37 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index b0e117a..cdd3352 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(); } From b9550ee2d7d7181af5e86e286bffe3feac92dcd1 Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 10:09:05 +0800 Subject: [PATCH 3/4] puyajun@huawei.com fix builderParam bug Signed-off-by: puyajun Change-Id: I84fa86b1ac77ec50dd2ada2eddf4d789cb42d143 --- compiler/test/ut/builder/builderParam.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index cdd3352..d21e640 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -46,7 +46,7 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - menuInfo: this.specificChild("menuInfo") + menuInfo: this.specificChild("menuInfo"), child: this.specificChild("child") }) } From 3ca8de59087b9b3c82b306c0ea7607c36194965c Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 10:13:04 +0800 Subject: [PATCH 4/4] puyajun@huawei.com fix builderParam bug Signed-off-by: puyajun Change-Id: Ic1de5e304086657b0f04d1bbbdf1e6fea9a18656 --- compiler/src/process_custom_component.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index e17abb5..a17447f 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -83,9 +83,9 @@ export function processCustomComponent(node: ts.ExpressionStatement, newStatemen argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => { if (isToChange(item, node.expression as ts.CallExpression)) { ischangeNode = true; - const PropertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( + const propertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( item, item.name, changeNodeFromCallToArrow(item.initializer as ts.CallExpression)); - argumentsArray.splice(index, 1, PropertyAssignmentNode); + argumentsArray.splice(index, 1, propertyAssignmentNode); } }); if (ischangeNode) { @@ -106,9 +106,9 @@ function isHasChild(node: ts.CallExpression): boolean { } function isToChange(item: ts.PropertyAssignment, node: ts.CallExpression): boolean { - const BuilderParamname = builderParamObjectCollection.get(node.expression.getText()); - return ts.isCallExpression(item.initializer) && BuilderParamname && - BuilderParamname.has(item.name.getText()); + 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 { @@ -152,8 +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) && isToChange( - item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { + if (isToChange(item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, item.name, changeNodeFromCallToArrow(item.initializer)); }