From c23c3c00782d5f222de9e024f58d3a919098b562 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Mon, 19 Sep 2022 11:21:38 +0800 Subject: [PATCH] Fix creating lexical env of for-statement on ts2abc Issue:I5S6Y3 Signed-off-by: ctw-ian Change-Id: I4186581f1738ac560330a5f1365f7287058f294f --- ts2panda/src/statement/loopStatement.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts index 4af9a4a576..476a5c437a 100644 --- a/ts2panda/src/statement/loopStatement.ts +++ b/ts2panda/src/statement/loopStatement.ts @@ -199,7 +199,6 @@ export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { compiler.popEnv(); pandaGen.freeTemps(...tmpVregs); } else { // compile for in fast mode - // createLoopEnv if needed if (needCreateLoopEnv) { pandaGen.createLexEnv(stmt, loopEnv, loopScope); compiler.pushEnv(loopEnv); @@ -214,9 +213,20 @@ export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { } } + if (needCreateLoopEnv) { + pandaGen.popLexicalEnv(stmt); + compiler.popEnv(); + } + // loopCondition pandaGen.label(stmt, loopStartLabel); + // createLoopEnv if needed + if (needCreateLoopEnv) { + pandaGen.createLexEnv(stmt, loopEnv, loopScope); + compiler.pushEnv(loopEnv); + } + if (stmt.condition) { compiler.compileCondition(stmt.condition, loopEndLabel); } -- Gitee