Skip to content

Commit 6fa24e8

Browse files
authored
fix(bundle): prevent tail-call in entry module for proper stack trace (#1678)
1 parent f15449f commit 6fa24e8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/transpilation/bundle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ export function getBundleResult(program: ts.Program, files: ProcessedFile[]): [t
110110

111111
// return require("<entry module path>")
112112
const args = options.luaTarget === LuaTarget.Lua50 ? "unpack(arg == nil and {} or arg)" : "...";
113-
const entryPoint = `return require(${createModulePath(entryModuleFilePath ?? entryModule, program)}, ${args})\n`;
113+
// Avoid producing a tail-call (which removes the bundle's stack frame) by assigning the `require` result to a local and returning it.
114+
const entryPath = createModulePath(entryModuleFilePath ?? entryModule, program);
115+
const entryPoint = `local ____entry = require(${entryPath}, ${args})\nreturn ____entry\n`;
114116

115117
const footers: string[] = [];
116118
if (options.sourceMapTraceback) {

0 commit comments

Comments
 (0)