Skip to content

Commit 58d0aee

Browse files
committed
fix sourceMapTraceback
1 parent 77b2d65 commit 58d0aee

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/lualib/SourceMapTraceBack.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// TODO: In the future, change this to __TS__RegisterFileInfo and provide tstl interface to
22
// get some metadata about transpilation.
3+
34
function __TS__SourceMapTraceBack(this: void, fileName: string, sourceMap: { [line: number]: number }): void {
45
globalThis.__TS__sourcemap = globalThis.__TS__sourcemap || {};
56
globalThis.__TS__sourcemap[fileName] = sourceMap;
@@ -9,9 +10,13 @@ function __TS__SourceMapTraceBack(this: void, fileName: string, sourceMap: { [li
910
debug.traceback = ((thread, message, level) => {
1011
let trace: string;
1112
if (thread === undefined && message === undefined && level === undefined) {
12-
trace = globalThis.__TS__originalTraceback();
13+
trace = (globalThis.__TS__originalTraceback as (this: void, ...args: any) => string)();
1314
} else {
14-
trace = globalThis.__TS__originalTraceback(thread, message, level);
15+
trace = (globalThis.__TS__originalTraceback as (this: void, ...args: any) => string)(
16+
thread,
17+
message,
18+
level
19+
);
1520
}
1621

1722
if (typeof trace !== "string") {

test/unit/printer/sourcemaps.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ test("sourceMapTraceback saves sourcemap in _G", () => {
272272
}
273273
});
274274

275+
test("sourceMapTraceback gives traceback", () => {
276+
const builder = util.testFunction`
277+
return (debug.traceback as (this: void)=>string)();
278+
`.setOptions({ sourceMapTraceback: true, luaLibImport: tstl.LuaLibImportKind.Inline });
279+
280+
const traceback = builder.getLuaExecutionResult();
281+
expect(traceback).toEqual(expect.any(String));
282+
});
283+
275284
test("Inline sourcemaps", () => {
276285
const code = `
277286
function abc() {

0 commit comments

Comments
 (0)