From f10e133e390127f39ce48f991d169b6548c0bf61 Mon Sep 17 00:00:00 2001 From: wangxiuxiu96 Date: Thu, 4 Sep 2025 21:08:08 +0800 Subject: [PATCH] =?UTF-8?q?[feate]=20=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E4=BA=92=E6=93=8D=E4=BD=9C-V1/V2=E6=B7=B7=E5=90=88=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=20=201.1=20=E8=B0=83=E7=94=A8=201.2=20=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangxiuxiu96 --- .../interop/src/process_custom_component.ts | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/compiler/src/interop/src/process_custom_component.ts b/compiler/src/interop/src/process_custom_component.ts index 7aaec808e..edf82c844 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); -- Gitee