Skip to content

Commit 5bcafb9

Browse files
committed
Fix sourcemaps when lualib_bundle is used
1 parent d129b3c commit 5bcafb9

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/LuaPrinter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ export class LuaPrinter {
175175
header += "{#SourceMapTraceback}\n";
176176
}
177177

178+
// Hack: __TS__Resolve macro resolution destroys mappings of macro's node grand-parent
179+
const headerNode = new SourceNode(null, null, null, new SourceNode(null, null, null, header));
178180
const fileBlockNode = this.printBlock(block);
179181

180-
return this.concatNodes(header, fileBlockNode);
182+
return this.concatNodes(headerNode, fileBlockNode);
181183
}
182184

183185
protected pushIndent(): void {

test/unit/printer/sourcemaps.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,23 @@ test.each([
5151
},
5252
{
5353
code: `
54-
// @ts-ignore
55-
import { Foo } from "foo";
54+
import { Foo } from "./module";
5655
Foo;
5756
`,
5857

5958
assertPatterns: [
60-
{ luaPattern: 'require("foo")', typeScriptPattern: '"foo"' },
59+
{ luaPattern: 'require("module")', typeScriptPattern: '"./module"' },
6160
{ luaPattern: "Foo", typeScriptPattern: "Foo" },
6261
],
6362
},
6463
{
6564
code: `
66-
// @ts-ignore
67-
import * as Foo from "foo";
65+
import * as Foo from "./module";
6866
Foo;
6967
`,
7068

7169
assertPatterns: [
72-
{ luaPattern: 'require("foo")', typeScriptPattern: '"foo"' },
70+
{ luaPattern: 'require("module")', typeScriptPattern: '"./module"' },
7371
{ luaPattern: "Foo", typeScriptPattern: "Foo" },
7472
],
7573
},
@@ -144,7 +142,11 @@ test.each([
144142
],
145143
},
146144
])("Source map has correct mapping (%p)", async ({ code, assertPatterns }) => {
147-
const file = util.testModule(code).expectToHaveNoDiagnostics().getMainLuaFileResult();
145+
const file = util
146+
.testModule(code)
147+
.addExtraFile("module.ts", "export const Foo = true;")
148+
.expectToHaveNoDiagnostics()
149+
.getMainLuaFileResult();
148150

149151
const consumer = await new SourceMapConsumer(file.luaSourceMap);
150152
for (const { luaPattern, typeScriptPattern } of assertPatterns) {

0 commit comments

Comments
 (0)