run lint

Signed-off-by: houhaoyu <houhaoyu@huawei.com>
Change-Id: I570584364ffb4f286e660786d38822da47377576
This commit is contained in:
houhaoyu
2022-08-19 17:05:12 +08:00
parent fa1d085011
commit 1ebf18e737
4 changed files with 36 additions and 36 deletions
+9 -9
View File
@@ -107,7 +107,7 @@ export function createLanguageService(rootFileNames: string[]): ts.LanguageServi
}
if (/(?<!\.d)\.(ets|ts)$/.test(fileName)) {
let content: string = processContent(fs.readFileSync(fileName).toString(), fileName);
let extendFunctionInfo: extendInfo[] = [];
const extendFunctionInfo: extendInfo[] = [];
content = instanceInsteadThis(content, fileName, extendFunctionInfo);
return ts.ScriptSnapshot.fromString(content);
}
@@ -243,7 +243,7 @@ export function createWatchCompilerHost(rootFileNames: string[],
}
if (/(?<!\.d)\.(ets|ts)$/.test(fileName)) {
let content: string = processContent(fs.readFileSync(fileName).toString(), fileName);
let extendFunctionInfo: extendInfo[] = [];
const extendFunctionInfo: extendInfo[] = [];
content = instanceInsteadThis(content, fileName, extendFunctionInfo);
return content;
}
@@ -255,13 +255,13 @@ export function createWatchCompilerHost(rootFileNames: string[],
function instanceInsteadThis(content: string, fileName: string, extendFunctionInfo: extendInfo[]): string {
checkUISyntax(content, fileName, extendFunctionInfo);
extendFunctionInfo.reverse().forEach((item)=>{
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));
+6 -6
View File
@@ -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,
+18 -18
View File
@@ -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,
+3 -3
View File
@@ -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) {