From f7a95466af526528552a09d9a8e97009711a45a7 Mon Sep 17 00:00:00 2001 From: puyajun Date: Thu, 20 Jan 2022 18:01:46 +0800 Subject: [PATCH] puyajun@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改builderbug Signed-off-by: puyajun Change-Id: Ibd36564595e5f7a4ccf183b005b2a6ad3387c599 --- compiler/src/process_component_build.ts | 3 ++- compiler/src/process_component_member.ts | 16 +++++-------- compiler/test/ut/builder/builderLambda.ts | 28 +++++++++-------------- compiler/test/ut/builder/builderParam.ts | 27 +++++++--------------- 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 59d7756d7..78d9fcebf 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -177,7 +177,8 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme case ComponentType.forEachComponent: processForEachComponent(item, newStatements, log); break; - case ComponentType.customBuilderMethod || ComponentType.builderParamMethod: + case ComponentType.customBuilderMethod: + case ComponentType.builderParamMethod: newStatements.push(item); break; } diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index dac38f476..0052cc917 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -104,7 +104,7 @@ export const setUpdateParamsDecorators: Set = ]); export const immutableDecorators: Set = - new Set([COMPONENT_STORAGE_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]); + new Set([COMPONENT_STORAGE_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR, COMPONENT_BUILDERPARAM_DECORATOR]); export const simpleTypes: Set = new Set([ts.SyntaxKind.StringKeyword, ts.SyntaxKind.NumberKeyword, ts.SyntaxKind.BooleanKeyword, ts.SyntaxKind.EnumDeclaration]); @@ -299,14 +299,16 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, } addAddProvidedVar(node, name, decorator, updateState); updateResult.setCtor(updateConstructor(ctorNode, [], [...updateState], false)); - updateResult.setVariableGet(createGetAccessor(name, CREATE_GET_METHOD)); + if (decorator !== COMPONENT_BUILDERPARAM_DECORATOR) { + updateResult.setVariableGet(createGetAccessor(name, CREATE_GET_METHOD)); + updateResult.setDeleteParams(true); + } if (!immutableDecorators.has(decorator)) { updateResult.setVariableSet(createSetAccessor(name, CREATE_SET_METHOD)); } if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); } - updateResult.setDeleteParams(true); } function processWatch(node: ts.PropertyDeclaration, decorator: ts.Decorator, @@ -436,14 +438,8 @@ function createUpdateParamsWithIf(name: ts.Identifier): ts.IfStatement { } function createUpdateParamsWithoutIf(name: ts.Identifier, isAdd: boolean = false): ts.ExpressionStatement { - let textName: string; - if (isAdd) { - textName = `__${name.getText()}`; - } else { - textName = name.getText(); - } return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( - createPropertyAccessExpressionWithThis(textName), + createPropertyAccessExpressionWithThis(name.getText()), ts.factory.createToken(ts.SyntaxKind.EqualsToken), createPropertyAccessExpressionWithParams(name.getText()))); } diff --git a/compiler/test/ut/builder/builderLambda.ts b/compiler/test/ut/builder/builderLambda.ts index 0bfa5adac..56d695a29 100644 --- a/compiler/test/ut/builder/builderLambda.ts +++ b/compiler/test/ut/builder/builderLambda.ts @@ -29,10 +29,10 @@ struct CustomContainer { } } -@Builder function specificParam(label1: string, label2: string) { +@Builder function specificParam() { Column() { - Text(label1) - Text(label2) + Text("label1") + Text("label2") } } @@ -47,7 +47,7 @@ struct CustomContainerUser { .width(50) Text("content2") } - specificParam("content3", "content4") + specificParam() } } } @@ -68,32 +68,26 @@ exports.expectResult = if (params.footer !== undefined) { this.footer = params.footer; } - this.__child = params.child; + this.child = params.child; } aboutToBeDeleted() { - this.__child.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } - get child() { - return this.__child.get(); - } - set child(newValue) { - this.__child.set(newValue); - } render() { Column.create(); Text.create(this.header); Text.pop(); + this.child(); Text.create(this.footer); Text.pop(); Column.pop(); } } -function specificParam(label1, label2) { +function specificParam() { Column.create(); - Text.create(label1); + Text.create("label1"); Text.pop(); - Text.create(label2); + Text.create("label2"); Text.pop(); Column.pop(); } @@ -121,7 +115,7 @@ class CustomContainerUser extends View { Text.create("content2"); Text.pop(); Column.pop(); - specificParam("content3", "content4"); + specificParam(); } })); } @@ -136,7 +130,7 @@ class CustomContainerUser extends View { Text.create("content2"); Text.pop(); Column.pop(); - specificParam("content3", "content4"); + specificParam(); } }); View.create(earlierCreatedChild_2); diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index bf41f3dd5..b0e117ad1 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -18,11 +18,11 @@ exports.source = ` struct CustomContainer { header: string = ""; footer: string = ""; - @BuilderParam child1: () => any; + @BuilderParam child: () => any; build() { Column() { - this.child1() + this.child() Text(this.header) Text(this.footer) } @@ -44,9 +44,8 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - }){ - this.specificChild() - } + child: this.specificChild + }) } } } @@ -66,20 +65,14 @@ exports.expectResult = if (params.footer !== undefined) { this.footer = params.footer; } - this.__child1 = params.child1; + this.child = params.child; } aboutToBeDeleted() { - this.__child1.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } - get child1() { - return this.__child1.get(); - } - set child1(newValue) { - this.__child1.set(newValue); - } render() { Column.create(); + this.child(); Text.create(this.header); Text.pop(); Text.create(this.footer); @@ -112,18 +105,14 @@ class CustomContainerUser extends View { View.create(new CustomContainer("2", this, { header: "Header", footer: "Footer", - child1: () => { - this.specificChild(); - } + child: this.specificChild })); } else { earlierCreatedChild_2.updateWithValueParams({ header: "Header", footer: "Footer", - child1: () => { - this.specificChild(); - } + child: this.specificChild }); View.create(earlierCreatedChild_2); } -- Gitee