diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 1a9cabc4238148d3c821660f9ef5b6966a50b5f7..d481454b485659f9f71ed4270df68596513cd030 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 7aaec808ec18bdb5c1c9b2c5d1cefbc0d12c9dd4..289036c524164b0c03d863f33dbd87514634e033 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 17baf35db8be0e6ec7b6a0c2d9a7fd763d20cf49..76ea76642e777dc636b12b12d1d102c92cf5a17f 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 c6ead9e7579c58f706bed4bf31c0081338ca862f..7fc4ade66429715e01b827601606c39b76db0c80 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 c799dbb2962e981c6b44fcaefee47c5cf11d00e9..3dc6193a80783aa3ce79ec55a2c2265d24826311 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" },