From 1ebf18e737206dc5e35da90c90fcace66de0f7ad Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Fri, 19 Aug 2022 17:05:12 +0800 Subject: [PATCH] houhaoyu@huawei.com run lint Signed-off-by: houhaoyu Change-Id: I570584364ffb4f286e660786d38822da47377576 --- compiler/src/ets_checker.ts | 18 ++++++------ compiler/src/process_component_build.ts | 12 ++++---- compiler/src/process_custom_component.ts | 36 ++++++++++++------------ compiler/src/process_ui_syntax.ts | 6 ++-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 11115a0..848f234 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -107,7 +107,7 @@ export function createLanguageService(rootFileNames: string[]): ts.LanguageServi } if (/(?{ - let subStr: string = content.substring(item.start,item.end); - let insert: string = subStr.replace(/(\s)this(\.)/g, (origin, item1, item2)=>{ + extendFunctionInfo.reverse().forEach((item) => { + const subStr: string = content.substring(item.start, item.end); + const insert: string = subStr.replace(/(\s)this(\.)/g, (origin, item1, item2) => { return item1 + item.compName + 'Instance' + item2; - }) + }); content = content.slice(0, item.start) + insert + content.slice(item.end); - }) + }); return content; } @@ -320,8 +320,8 @@ function parseAllNode(node: ts.Node, sourceFileNode: ts.SourceFile, extendFuncti } if (ts.isFunctionDeclaration(node) && hasDecorator(node, COMPONENT_EXTEND_DECORATOR)) { if (node.body && node.body.statements && node.body.statements.length && - !(isOriginalExtend(node.body))) { - extendFunctionInfo.push({start:node.pos, end:node.end, compName: isExtendFunction(node)}) + !isOriginalExtend(node.body)) { + extendFunctionInfo.push({start: node.pos, end: node.end, compName: isExtendFunction(node)}); } } node.getChildren().forEach((item: ts.Node) => parseAllNode(item, sourceFileNode, extendFunctionInfo)); diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 62b2255..75ecef9 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -1160,9 +1160,9 @@ function traverseStateStylesAttr(temp: any, statements: ts.Statement[], bindComponentAttr(ts.factory.createExpressionStatement( item.initializer.properties[0].initializer), identifierNode, statements, log, false, true); } else { - if (!(ts.isObjectLiteralExpression(item.initializer) && item.initializer.properties.length === 0)) { - validateStateStyleSyntax(temp, log); - } + if (!(ts.isObjectLiteralExpression(item.initializer) && item.initializer.properties.length === 0)) { + validateStateStyleSyntax(temp, log); + } } if (item.name) { statements.push(createViewStackProcessor(item, false)); @@ -1333,7 +1333,7 @@ function getComponentType(node: ts.ExpressionStatement, log: LogInfo[], } else if (builderParamObjectCollection.get(componentCollection.currentClassName) && builderParamObjectCollection.get(componentCollection.currentClassName).has(name)) { return ComponentType.builderParamMethod; - } else if ((parent === 'Column' || parent === 'XComponent' || CUSTOM_BUILDER_METHOD.has(parent)) && + } else if ((['Column', 'XComponent'].includes(parent) || CUSTOM_BUILDER_METHOD.has(parent)) && ts.isCallExpression(node.expression) && ts.isIdentifier(node.expression.expression)) { return ComponentType.function; } else if (!isAttributeNode(node)) { @@ -1356,7 +1356,7 @@ export function validateStateStyleSyntax(temp: any, log: LogInfo[]): void { function getEtsComponentExpression(node:ts.ExpressionStatement): ts.EtsComponentExpression { let current: any = node.expression; - while(current) { + while (current) { if (ts.isEtsComponentExpression(current)) { return current; } @@ -1366,7 +1366,7 @@ function getEtsComponentExpression(node:ts.ExpressionStatement): ts.EtsComponent } function checkEtsComponent(node: ts.ExpressionStatement, log: LogInfo[]): void { - const etsComponentExpression: ts.EtsComponentExpression = getEtsComponentExpression(node); + const etsComponentExpression: ts.EtsComponentExpression = getEtsComponentExpression(node); if (etsComponentExpression) { checkAllNode( etsComponentExpression, diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 6c6e652..f1e5187 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -363,28 +363,28 @@ function createFindChildById(id: string, name: string, isInnerBuilder: boolean = return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( [ts.factory.createVariableDeclaration(ts.factory.createIdentifier( `${CUSTOM_COMPONENT_EARLIER_CREATE_CHILD}${id}`), undefined, ts.factory.createTypeReferenceNode( - ts.factory.createIdentifier(name)), - ts.factory.createConditionalExpression( - ts.factory.createParenthesizedExpression( + ts.factory.createIdentifier(name)), + ts.factory.createConditionalExpression( + ts.factory.createParenthesizedExpression( ts.factory.createBinaryExpression( ts.factory.createThis(), ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken), - ts.factory.createPropertyAccessExpression( - ts.factory.createThis(), - ts.factory.createIdentifier(CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID) - ))),ts.factory.createToken(ts.SyntaxKind.QuestionToken), + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID) + ))), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createAsExpression(ts.factory.createCallExpression( - ts.factory.createPropertyAccessExpression(isInnerBuilder ? - ts.factory.createParenthesizedExpression(ts.factory.createConditionalExpression( - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), - ts.factory.createToken(ts.SyntaxKind.QuestionToken), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), - ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createThis() - )) : ts.factory.createThis(), ts.factory.createIdentifier( - `${CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID}`)), undefined, [ts.factory.createStringLiteral(id)]), - ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))), - ts.factory.createToken(ts.SyntaxKind.ColonToken), - ts.factory.createIdentifier("undefined")))], ts.NodeFlags.Let)); + ts.factory.createPropertyAccessExpression(isInnerBuilder ? + ts.factory.createParenthesizedExpression(ts.factory.createConditionalExpression( + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createToken(ts.SyntaxKind.QuestionToken), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createThis() + )) : ts.factory.createThis(), ts.factory.createIdentifier( + `${CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID}`)), undefined, [ts.factory.createStringLiteral(id)]), + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))), + ts.factory.createToken(ts.SyntaxKind.ColonToken), + ts.factory.createIdentifier('undefined')))], ts.NodeFlags.Let)); } function createCustomComponentIfStatement(id: string, node: ts.ExpressionStatement, diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index ab99a17..f89cbcf 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -444,11 +444,11 @@ function processExtend(node: ts.FunctionDeclaration, log: LogInfo[]): ts.Functio return ts.factory.updateFunctionDeclaration(node, undefined, node.modifiers, node.asteriskToken, ts.factory.createIdentifier(extendFunctionName), node.typeParameters, node.parameters, node.type, isOriginalExtend(node.body) ? - ts.factory.updateBlock(node.body, statementArray) : bodynode); + ts.factory.updateBlock(node.body, statementArray) : bodynode); } function traverseExtendExpression(node: ts.Node): ts.Node { if (ts.isExpressionStatement(node) && isThisNode(node)) { - let changeCompName: ts.ExpressionStatement = + const changeCompName: ts.ExpressionStatement = ts.factory.createExpressionStatement(processExtendBody(node.expression, componentName)); const statementArray: ts.Statement[] = []; bindComponentAttr(changeCompName, ts.factory.createIdentifier(componentName), statementArray, []); @@ -477,7 +477,7 @@ export function isOriginalExtend(node: ts.Block): boolean { function isThisNode(node: ts.ExpressionStatement): boolean { let innerNode: ts.Node = node; - while(innerNode.expression) { + while (innerNode.expression) { innerNode = innerNode.expression; } if (innerNode.kind === ts.SyntaxKind.ThisKeyword) {