Skip to content

Commit 37e07bb

Browse files
committed
fix: replace the top-level context only
1 parent df8a750 commit 37e07bb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

modules/code-generator/src/utils/expressionParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export function parseExpressionConvertThis2Context(
271271

272272
const localVariablesSet = new Set(localVariables);
273273

274-
let thisScopeLevel = CROSS_THIS_SCOPE_TYPE_NODE[exprAst.type] ? -1 : 0;
274+
let thisScopeLevel = -1;
275275
traverse(fileAst, {
276276
enter(path) {
277277
if (CROSS_THIS_SCOPE_TYPE_NODE[path.node.type]) {
@@ -303,7 +303,7 @@ export function parseExpressionConvertThis2Context(
303303
}
304304

305305
// 替换 this (只在顶层替换)
306-
if (thisScopeLevel <= 0) {
306+
if (thisScopeLevel === 0) {
307307
obj.replaceWith(t.identifier(contextName));
308308
}
309309
},
@@ -317,7 +317,7 @@ export function parseExpressionConvertThis2Context(
317317
return;
318318
}
319319

320-
if (thisScopeLevel <= 0) {
320+
if (thisScopeLevel === 0) {
321321
path.replaceWith(t.identifier(contextName));
322322
}
323323
},

0 commit comments

Comments
 (0)