diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 4818a0fd771cee14fc0bef2ed1999c23ae0a81d5..3562d2a4f18f0b6e3f79a72f7cba94bf871a9e31 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -468,7 +468,14 @@ export class Compiler { this.pushScope(block); hoistFunctionInBlock(this.scope, this.pandaGen, isStrictMode(block), this); - block.statements.forEach((stmt) => this.compileStatement(stmt)); + for (let i = 0; i < block.statements.length; ++i) { + let stmt = block.statements[i]; + this.compileStatement(stmt); + if (stmt.kind == ts.SyntaxKind.ReturnStatement) { + this.popScope(); + return; + } + } this.popScope(); }