!980 this=>$ in @Extend

Merge pull request !980 from houhaoyu/master18
This commit is contained in:
openharmony_ci
2022-08-21 08:31:57 +00:00
committed by Gitee
2 changed files with 5 additions and 9 deletions
+1 -1
View File
@@ -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);
+4 -8
View File
@@ -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;
}
}