From b21b49100cf08a59521bdd42a855aab03e0f8a1d Mon Sep 17 00:00:00 2001 From: Yenan Date: Thu, 10 Jul 2025 17:53:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=AD=E8=A8=80=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=A2=AB=E5=BD=93=E5=81=9A=E5=8F=8C=E5=90=91=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E6=A0=A1=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yenan --- compiler/src/process_component_build.ts | 2 +- compiler/src/process_custom_component.ts | 8 ++++++-- compiler/src/process_struct_componentV2.ts | 3 ++- .../process_custom_component/validateParamTwoWayBind.ets | 2 ++ compiler/test/transform_ut_error.json | 6 +++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 1a9cabc42..d481454b4 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -755,7 +755,7 @@ function processExpressionStatementChange(node: ts.ExpressionStatement, nextNode log.push({ type: LogType.ERROR, message: `In the trailing lambda case, '${name}' must have one and only one property decorated with ` + - `'@BuilderParam', and its '@BuilderParam' expects no parameter.`, + `'@BuilderParam'.`, pos: node.getStart(), code: '10905102' }); diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 7aaec808e..289036c52 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -865,7 +865,7 @@ function getNewArgsForCustomComponent(childParam: ts.Expression[], function updatePropertyAssignment(newProperties: ts.PropertyAssignment[], itemName: string, item: ts.PropertyAssignment, childStructInfo: StructInfo, log: LogInfo[]): void { - if (isDoubleNonNullExpression(item.initializer)) { + if (isDoubleNonNullExpression(item.initializer) && !moreThanDoubleNonNull(item.initializer)) { if (isLeftHandExpression(item.initializer.expression.expression)) { const result: Record = { hasQuestionToken: false }; traverseExpressionNode(item.initializer.expression.expression, result); @@ -932,6 +932,10 @@ function isDoubleNonNullExpression(node: ts.Expression): boolean { return node && ts.isNonNullExpression(node) && ts.isNonNullExpression(node.expression); } +function moreThanDoubleNonNull(node: ts.Expression): boolean { + return node && ts.isNonNullExpression(node) && ts.isNonNullExpression(node.expression) && ts.isNonNullExpression(node.expression.expression); +} + function isLeftHandExpression(node: ts.Expression): boolean { return node && (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)); } @@ -1426,7 +1430,7 @@ function getForbbiddenToInitViaParamType(customComponentName: string, const propName: string = node.escapedText.toString(); if (getCollectionSet(customComponentName, storageLinkCollection).has(propName)) { propType = COMPONENT_STORAGE_LINK_DECORATOR; - } else if (getCollectionSet(customComponentName, storagePropCollection)) { + } else if (getCollectionSet(customComponentName, storagePropCollection).has(propName)) { propType = COMPONENT_STORAGE_PROP_DECORATOR; } else if (ifLocalStorageLink(customComponentName, propName)) { propType = COMPONENT_LOCAL_STORAGE_LINK_DECORATOR; diff --git a/compiler/src/process_struct_componentV2.ts b/compiler/src/process_struct_componentV2.ts index 17baf35db..76ea76642 100644 --- a/compiler/src/process_struct_componentV2.ts +++ b/compiler/src/process_struct_componentV2.ts @@ -593,7 +593,8 @@ function checkParamDecorator(propertyDecorator: PropertyDecorator, member: ts.Pr } if (propertyDecorator.hasRequire && !propertyDecorator.hasParam && !checkHasBuilderParamDecorator(propertyDecorator, member, sourceFileNode, structInfo)) { - const message: string = 'In a struct decorated with \'@ComponentV2\', \'@Require\' can only be used with \'@Param\'.'; + const message: string = 'In a struct decorated with \'@ComponentV2\', \'@Require\' can only be used with \'@Param\'' + + ' and \'@BuilderParam\'.'; addLog(LogType.ERROR, message, member.getStart(), log, sourceFileNode, { code: '10905325' }); } } diff --git a/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_custom_component/validateParamTwoWayBind.ets b/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_custom_component/validateParamTwoWayBind.ets index c6ead9e75..7fc4ade66 100644 --- a/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_custom_component/validateParamTwoWayBind.ets +++ b/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_custom_component/validateParamTwoWayBind.ets @@ -41,6 +41,8 @@ struct validateParamTwoWayBind { testParamChild2({paramValue: this.aa()?.gloabel_value!!}) testParamChild2({paramValue: this.bb()!!}) testParamChild2({paramValue: "hello"!!}) + testParamChild2({paramValue: "hello"!!!}) + testParamChild2({paramValue: this.local_value!!!}) } } } diff --git a/compiler/test/transform_ut_error.json b/compiler/test/transform_ut_error.json index c799dbb29..3dc6193a8 100644 --- a/compiler/test/transform_ut_error.json +++ b/compiler/test/transform_ut_error.json @@ -22,7 +22,7 @@ "code": "10905209" }, "@BuilderParam": { - "message": "In the trailing lambda case, 'CustomContainer' must have one and only one property decorated with '@BuilderParam', and its '@BuilderParam' expects no parameter.", + "message": "In the trailing lambda case, 'CustomContainer' must have one and only one property decorated with '@BuilderParam'.", "type": "ERROR", "code": "10905102" }, @@ -737,12 +737,12 @@ "code": "10905327" }, { - "message": "In a struct decorated with '@ComponentV2', '@Require' can only be used with '@Param'.", + "message": "In a struct decorated with '@ComponentV2', '@Require' can only be used with '@Param' and '@BuilderParam'.", "type": "ERROR", "code": "10905325" }, { - "message": "In a struct decorated with '@ComponentV2', '@Require' can only be used with '@Param'.", + "message": "In a struct decorated with '@ComponentV2', '@Require' can only be used with '@Param' and '@BuilderParam'.", "type": "ERROR", "code": "10905325" }, -- Gitee