From fbe1ef8a447affd2aa91af4362e6ed5445cab2eb Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Wed, 10 May 2023 16:54:26 +0800 Subject: [PATCH] Stop compiling blockStatement when encountering returnStatment Issue:I72014 Signed-off-by: gavin1012_hw Change-Id: Id1c920f742243267e21a1a86eb162212a6414496 --- ts2panda/src/compiler.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 4818a0fd77..3562d2a4f1 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(); } -- Gitee