diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts index 4af9a4a5766df9df14ea1490c8629f7359689ce2..476a5c437ab3dff9e879ace04b2998c4811c3f47 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); }