From e2a51b864a063485779303ce79827943ecb38413 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 5 May 2022 19:07:27 +0800 Subject: [PATCH 1/4] bugFix: fixed component params validate Signed-off-by: laibo102 Change-Id: I535e358e0daa80db53a3f18bf2537048bd5e235b --- compiler/src/process_custom_component.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index f0dc864..e18502b 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -153,22 +153,16 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string if (item.name && ts.isIdentifier(item.name)) { curChildProps.add(item.name.escapedText.toString()); } - if (isThisProperty(item, propertySet)) { - validateStateManagement(item, name, log); - if (isNonThisProperty(item, linkSet)) { - if (isToChange(item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { - item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, - item.name, changeNodeFromCallToArrow(item.initializer)); - } - props.push(item); + validateStateManagement(item, name, log); + if (isNonThisProperty(item, linkSet)) { + if (isToChange(item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { + item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, + item.name, changeNodeFromCallToArrow(item.initializer)); } - } else { - validateNonExistentProperty(item, name, log); + props.push(item); } }); } - validateMandatoryToAssignmentViaParam(node, name, curChildProps, log); - validateMandatoryToInitViaParam(node, name, curChildProps, log); } function getCustomComponentName(newNode: ts.NewExpression): string { From cda5ebcf2d6963cd2c3b1e2850cc86d08c5f3bee Mon Sep 17 00:00:00 2001 From: laibo102 Date: Sat, 7 May 2022 17:17:46 +0800 Subject: [PATCH 2/4] bugFix: fixed component params validate Signed-off-by: laibo102 Change-Id: I585eb246554766b567eecc39e9f0afeadf952403 --- compiler/src/process_component_class.ts | 36 ++++++++++-------------- compiler/src/process_custom_component.ts | 6 +++- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 7ccefb1..12c8089 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -230,8 +230,7 @@ function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], } function createPropertyDeclaration(propertyItem: ts.PropertyDeclaration, newType: ts.TypeNode | undefined, - normalVar: boolean, isLocalStorage: boolean = false, parentComponentName: string = null - ): ts.PropertyDeclaration { + normalVar: boolean, isLocalStorage: boolean = false, parentComponentName: string = null): ts.PropertyDeclaration { if (typeof newType === undefined) { return undefined; } @@ -418,27 +417,22 @@ export function createReference(node: ts.PropertyAssignment): ts.PropertyAssignm const linkParentComponent: string[] = getParentNode(node, linkCollection).slice(1); const propertyName: ts.Identifier = node.name as ts.Identifier; let initText: string; - if (linkParentComponent && ts.isPropertyAssignment(node) && ts.isIdentifier(propertyName) && - linkParentComponent.includes(propertyName.escapedText.toString())) { - const LINK_REG: RegExp = /^\$/g; - const initExpression: ts.Expression = node.initializer; - if (ts.isIdentifier(initExpression) && - initExpression.escapedText.toString().match(LINK_REG)) { - if (linkParentComponent.includes(propertyName.escapedText.toString())) { - initText = initExpression.escapedText.toString().replace(LINK_REG, ''); - } - } else if (ts.isPropertyAccessExpression(initExpression) && initExpression.expression && - initExpression.expression.kind === ts.SyntaxKind.ThisKeyword && - ts.isIdentifier(initExpression.name) && - initExpression.name.escapedText.toString().match(LINK_REG)) { - if (linkParentComponent.includes(propertyName.escapedText.toString())) { - initText = initExpression.name.escapedText.toString().replace(LINK_REG, ''); - } - } - if (initText) { - node = addDoubleUnderline(node, propertyName, initText); + const LINK_REG: RegExp = /^\$/g; + const initExpression: ts.Expression = node.initializer; + if (ts.isIdentifier(initExpression) && + initExpression.escapedText.toString().match(LINK_REG)) { + initText = initExpression.escapedText.toString().replace(LINK_REG, ''); + } else if (ts.isPropertyAccessExpression(initExpression) && initExpression.expression && + initExpression.expression.kind === ts.SyntaxKind.ThisKeyword && + ts.isIdentifier(initExpression.name) && + initExpression.name.escapedText.toString().match(LINK_REG)) { + if (linkParentComponent.includes(propertyName.escapedText.toString())) { + initText = initExpression.name.escapedText.toString().replace(LINK_REG, ''); } } + if (initText) { + node = addDoubleUnderline(node, propertyName, initText); + } return node; } diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index e18502b..0c78a2f 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -108,7 +108,7 @@ function isHasChild(node: ts.CallExpression): boolean { function isToChange(item: ts.PropertyAssignment, node: ts.CallExpression): boolean { const builderParamName: Set = builderParamObjectCollection.get(node.expression.getText()); if (item.initializer && ts.isCallExpression(item.initializer) && builderParamName && - builderParamName.has(item.name.getText()) && + builderParamName.has(item.name.getText()) && !/\.(bind|call|apply)/.test(item.initializer.getText())) { return true; } @@ -191,6 +191,10 @@ function isThisProperty(node: ts.ObjectLiteralElementLike, propertySet: Set): boolean { + if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && + node.initializer.escapedText && node.initializer.escapedText.includes('$')) { + return false; + } if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && !propertySet.has(node.name.escapedText.toString())) { return true; From edd9c1eaf89838a9b711eb85c78df2bb54b9e07f Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 9 May 2022 18:22:48 +0800 Subject: [PATCH 3/4] fixed component params validate Signed-off-by: laibo102 Change-Id: Id13d4eb22bb2458f74217571e318484560f23069 --- compiler/src/process_component_class.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 12c8089..b72c7db 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -422,10 +422,7 @@ export function createReference(node: ts.PropertyAssignment): ts.PropertyAssignm if (ts.isIdentifier(initExpression) && initExpression.escapedText.toString().match(LINK_REG)) { initText = initExpression.escapedText.toString().replace(LINK_REG, ''); - } else if (ts.isPropertyAccessExpression(initExpression) && initExpression.expression && - initExpression.expression.kind === ts.SyntaxKind.ThisKeyword && - ts.isIdentifier(initExpression.name) && - initExpression.name.escapedText.toString().match(LINK_REG)) { + } else if (isMatchInitExpression(initExpression) && initExpression.name.escapedText.toString().match(LINK_REG)) { if (linkParentComponent.includes(propertyName.escapedText.toString())) { initText = initExpression.name.escapedText.toString().replace(LINK_REG, ''); } @@ -436,6 +433,13 @@ export function createReference(node: ts.PropertyAssignment): ts.PropertyAssignm return node; } +function isMatchInitExpression(initExpression: ts.Expression): boolean { + return ts.isPropertyAccessExpression(initExpression) && + initExpression.expression && + initExpression.expression.kind === ts.SyntaxKind.ThisKeyword && + ts.isIdentifier(initExpression.name); +} + function addDoubleUnderline(node: ts.PropertyAssignment, propertyName: ts.Identifier, initText: string): ts.PropertyAssignment { return ts.factory.updatePropertyAssignment(node, propertyName, From a8f1cf4e1c29d186a47e84a7d2e87a7c31fea9d9 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 12 May 2022 18:03:35 +0800 Subject: [PATCH 4/4] merge if Signed-off-by: laibo102 Change-Id: Ib7feef416e1b8717c217129d08c0c3ddb1663f4c --- compiler/src/process_component_class.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index b72c7db..619eca4 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -422,10 +422,10 @@ export function createReference(node: ts.PropertyAssignment): ts.PropertyAssignm if (ts.isIdentifier(initExpression) && initExpression.escapedText.toString().match(LINK_REG)) { initText = initExpression.escapedText.toString().replace(LINK_REG, ''); - } else if (isMatchInitExpression(initExpression) && initExpression.name.escapedText.toString().match(LINK_REG)) { - if (linkParentComponent.includes(propertyName.escapedText.toString())) { - initText = initExpression.name.escapedText.toString().replace(LINK_REG, ''); - } + } else if (isMatchInitExpression(initExpression) && + initExpression.name.escapedText.toString().match(LINK_REG) && + linkParentComponent.includes(propertyName.escapedText.toString())) { + initText = initExpression.name.escapedText.toString().replace(LINK_REG, ''); } if (initText) { node = addDoubleUnderline(node, propertyName, initText);