From 0a4ff0d617f8723a744d8fa26c26312a874df01a Mon Sep 17 00:00:00 2001 From: Yaroslav <63865083+dnrovs@users.noreply.github.com> Date: Thu, 22 Jan 2026 19:13:39 +0200 Subject: [PATCH] fix(bundle): prevent tail-call in entry module for proper stack trace --- src/transpilation/bundle.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/transpilation/bundle.ts b/src/transpilation/bundle.ts index 1e0436c35..b030bddfe 100644 --- a/src/transpilation/bundle.ts +++ b/src/transpilation/bundle.ts @@ -110,7 +110,9 @@ export function getBundleResult(program: ts.Program, files: ProcessedFile[]): [t // return require("") const args = options.luaTarget === LuaTarget.Lua50 ? "unpack(arg == nil and {} or arg)" : "..."; - const entryPoint = `return require(${createModulePath(entryModuleFilePath ?? entryModule, program)}, ${args})\n`; + // Avoid producing a tail-call (which removes the bundle's stack frame) by assigning the `require` result to a local and returning it. + const entryPath = createModulePath(entryModuleFilePath ?? entryModule, program); + const entryPoint = `local ____entry = require(${entryPath}, ${args})\nreturn ____entry\n`; const footers: string[] = []; if (options.sourceMapTraceback) {