mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-08-26 18:46:33 -04:00
!623 fixed component params validate
Merge pull request !623 from laibo102/master
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user