!623 fixed component params validate

Merge pull request !623 from laibo102/master
This commit is contained in:
openharmony_ci
2022-05-13 03:16:23 +00:00
committed by Gitee
2 changed files with 30 additions and 34 deletions
+19 -21
View File
@@ -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,
+11 -13
View File
@@ -108,7 +108,7 @@ function isHasChild(node: ts.CallExpression): boolean {
function isToChange(item: ts.PropertyAssignment, node: ts.CallExpression): boolean {
const builderParamName: Set<string> = 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<stri
}
function isNonThisProperty(node: ts.ObjectLiteralElementLike, propertySet: Set<string>): 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;