From f721f24bff6c3dd4489bc003ce2e9154093532df Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Sat, 20 Aug 2022 20:58:54 +0800 Subject: [PATCH] houhaoyu@huawei.com change this to dollar in extend Signed-off-by: houhaoyu Change-Id: I1d0be0faa27ba4f5913736697fb8c7c6aabeb698 --- compiler/src/ets_checker.ts | 2 +- compiler/src/process_ui_syntax.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 848f234..6dab74f 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -257,7 +257,7 @@ function instanceInsteadThis(content: string, fileName: string, extendFunctionIn checkUISyntax(content, fileName, extendFunctionInfo); extendFunctionInfo.reverse().forEach((item) => { const subStr: string = content.substring(item.start, item.end); - const insert: string = subStr.replace(/(\s)this(\.)/g, (origin, item1, item2) => { + const insert: string = subStr.replace(/(\s)\$(\.)/g, (origin, item1, item2) => { return item1 + item.compName + 'Instance' + item2; }); content = content.slice(0, item.start) + insert + content.slice(item.end); diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index f89cbcf..5edb69c 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -447,7 +447,7 @@ function processExtend(node: ts.FunctionDeclaration, log: LogInfo[]): ts.Functio ts.factory.updateBlock(node.body, statementArray) : bodynode); } function traverseExtendExpression(node: ts.Node): ts.Node { - if (ts.isExpressionStatement(node) && isThisNode(node)) { + if (ts.isExpressionStatement(node) && isDollarNode(node)) { const changeCompName: ts.ExpressionStatement = ts.factory.createExpressionStatement(processExtendBody(node.expression, componentName)); const statementArray: ts.Statement[] = []; @@ -475,12 +475,12 @@ export function isOriginalExtend(node: ts.Block): boolean { return false; } -function isThisNode(node: ts.ExpressionStatement): boolean { +function isDollarNode(node: ts.ExpressionStatement): boolean { let innerNode: ts.Node = node; while (innerNode.expression) { innerNode = innerNode.expression; } - if (innerNode.kind === ts.SyntaxKind.ThisKeyword) { + if (ts.isIdentifier(innerNode) && innerNode.getText() === '$') { return true; } else { return false; @@ -498,13 +498,9 @@ function processExtendBody(node: ts.Node, componentName?: string): ts.Expression case ts.SyntaxKind.Identifier: if (!componentName) { return ts.factory.createIdentifier(node.escapedText.toString().replace(INSTANCE, '')); - } - break; - case ts.SyntaxKind.ThisKeyword: - if (componentName) { + } else { return ts.factory.createIdentifier(componentName); } - break; } }