diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 78c3fc8..316f670 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; } @@ -419,30 +418,29 @@ 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) && + 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 (isMatchInitExpression(initExpression) && + initExpression.name.escapedText.toString().match(LINK_REG) && 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); - } + initText = initExpression.name.escapedText.toString().replace(LINK_REG, ''); + } + if (initText) { + node = addDoubleUnderline(node, propertyName, initText); } 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, diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index f0dc864..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; } @@ -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 { @@ -197,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;