From 37e07bb238396942e11e16719859bc60da34f166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Fri, 10 Feb 2023 22:10:17 +0800 Subject: [PATCH] fix: replace the top-level context only --- modules/code-generator/src/utils/expressionParser.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/code-generator/src/utils/expressionParser.ts b/modules/code-generator/src/utils/expressionParser.ts index cbc950bbc..fc1fe4195 100644 --- a/modules/code-generator/src/utils/expressionParser.ts +++ b/modules/code-generator/src/utils/expressionParser.ts @@ -271,7 +271,7 @@ export function parseExpressionConvertThis2Context( const localVariablesSet = new Set(localVariables); - let thisScopeLevel = CROSS_THIS_SCOPE_TYPE_NODE[exprAst.type] ? -1 : 0; + let thisScopeLevel = -1; traverse(fileAst, { enter(path) { if (CROSS_THIS_SCOPE_TYPE_NODE[path.node.type]) { @@ -303,7 +303,7 @@ export function parseExpressionConvertThis2Context( } // 替换 this (只在顶层替换) - if (thisScopeLevel <= 0) { + if (thisScopeLevel === 0) { obj.replaceWith(t.identifier(contextName)); } }, @@ -317,7 +317,7 @@ export function parseExpressionConvertThis2Context( return; } - if (thisScopeLevel <= 0) { + if (thisScopeLevel === 0) { path.replaceWith(t.identifier(contextName)); } },