diff --git a/compiler/src/interop/src/process_custom_component.ts b/compiler/src/interop/src/process_custom_component.ts index 7aaec808ec18bdb5c1c9b2c5d1cefbc0d12c9dd4..edf82c84448d733ccc69bd6b89cad025982449de 100644 --- a/compiler/src/interop/src/process_custom_component.ts +++ b/compiler/src/interop/src/process_custom_component.ts @@ -366,6 +366,8 @@ class ChildAndParentComponentInfo { propsAndObjectLinks: string[]; childName: string; forbiddenInitPropsV2: string[]; + forbiddenInitPropsV2New: string[]; + forbiddenInitPropsV1: string[]; updatePropsForV1Parent: string[]; updatePropsForV2Parent: string[]; constructor(childName: string, childNode: ts.CallExpression, propsAndObjectLinks: string[]) { @@ -380,11 +382,17 @@ class ChildAndParentComponentInfo { new StructInfo(); this.forbiddenInitPropsV2 = [...this.childStructInfo.localDecoratorSet, ...this.childStructInfo.providerDecoratorSet, ...this.childStructInfo.consumerDecoratorSet, - ...this.childStructInfo.regularSet]; + ...this.childStructInfo.regularSet ]; + this.forbiddenInitPropsV2New = [...this.childStructInfo.localDecoratorSet, + ...this.childStructInfo.providerDecoratorSet, ...this.childStructInfo.consumerDecoratorSet, + ...this.childStructInfo.regularSet, ...this.parentStructInfo.paramDecoratorMap.keys(), + ...this.parentStructInfo.eventDecoratorMap.keys()]; this.updatePropsForV1Parent = getUpdatePropsForV1Parent(); this.updatePropsForV2Parent = [...this.parentStructInfo.localDecoratorSet, ...this.parentStructInfo.paramDecoratorMap.keys(), ...this.parentStructInfo.providerDecoratorSet, - ...this.parentStructInfo.consumerDecoratorSet]; + ...this.parentStructInfo.consumerDecoratorSet ]; + this.forbiddenInitPropsV1 = [...this.childStructInfo.updatePropsDecoratorsV1, + ...this.childStructInfo.linkDecoratorsV1 ]; } } @@ -435,8 +443,53 @@ function getForbbidenInitPropsV2Type(itemName: string, info: ChildAndParentCompo return typeName; } +function getForbbidenInitPropsV1Type(itemName: string, info: ChildAndParentComponentInfo): string { + let typeName: string = COMPONENT_NON_DECORATOR; + if (info.childStructInfo.updatePropsDecoratorsV1.includes(itemName)) { + typeName = 'state variable'; + } else if (info.childStructInfo.linkDecoratorsV1.includes(itemName)) { + typeName = COMPONENT_LINK_DECORATOR; + } + return typeName; +} + function validateChildProperty(item: ts.PropertyAssignment, itemName: string, - childParam: ts.PropertyAssignment[], log: LogInfo[], info: ChildAndParentComponentInfo): void { + childParam: ts.PropertyAssignment[], log: LogInfo[], info: ChildAndParentComponentInfo ): void +{ + // 1.1 invoke 1.2, V1 invoke V2 + if (!info.parentStructInfo.isComponentV2 && info.childStructInfo.isComponentV2) + { + if (info.forbiddenInitPropsV2New.includes(itemName)) + { + const propType: string = getForbbidenInitPropsV2Type(itemName, info); + log.push({ + type: LogType.ERROR, + message: `zhaopp The '${propType}' property '${itemName}' in the custom component '${info.childName}'` + + ` cannot be initialized here (forbidden to specify).`, + pos: item.getStart(), + code: '10905324' + }); + return; + } + } + + // 1.1 invoke 1.2, V2 invoke V1 + if (info.parentStructInfo.isComponentV2 && !info.childStructInfo.isComponentV2) + { + if (info.forbiddenInitPropsV1.includes(itemName)) + { + const propType: string = getForbbidenInitPropsV1Type(itemName, info); + log.push({ + type: LogType.ERROR, + message: `zhaopp The '${propType}' property '${itemName}' in the custom component '${info.childName}'` + + ` cannot be initialized here (forbidden to specify).`, + pos: item.getStart(), + code: '10905324' + }); + return; + } + } + if (info.childStructInfo.isComponentV2) { if (info.forbiddenInitPropsV2.includes(itemName)) { const propType: string = getForbbidenInitPropsV2Type(itemName, info);