Skip to content

Commit dd7e5de

Browse files
tomblindPerryvw
authored andcommitted
fixed commenting of inline sourcemaps (#519)
* fixed commenting of inline sourcemaps and added test * forgot to run prettier
1 parent 4fbf086 commit dd7e5de

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/LuaPrinter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class LuaPrinter {
8383
const map = sourceMap.toString();
8484
const base64Map = Buffer.from(map).toString('base64');
8585

86-
return `//# sourceMappingURL=data:application/json;base64,${base64Map}\n`;
86+
return `--# sourceMappingURL=data:application/json;base64,${base64Map}\n`;
8787
}
8888

8989
private printStackTraceOverride(rootNode: SourceNode): string {

test/unit/sourcemaps.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as util from "../util";
2-
import { LuaLibImportKind } from "../../src/CompilerOptions";
2+
import { LuaLibImportKind, CompilerOptions } from "../../src/CompilerOptions";
33
import { SourceMapConsumer, Position } from "source-map";
44

55
test.each([
@@ -109,6 +109,33 @@ test("sourceMapTraceback saves sourcemap in _G", () => {
109109
}
110110
});
111111

112+
test("Inline sourcemaps", () => {
113+
const typeScriptSource = `
114+
function abc() {
115+
return def();
116+
}
117+
function def() {
118+
return "foo";
119+
}
120+
return abc();`;
121+
122+
const compilerOptions: CompilerOptions = {
123+
inlineSourceMap: true,
124+
};
125+
126+
const { lua, sourceMap } = util.transpileStringResult(typeScriptSource, compilerOptions);
127+
128+
const inlineSourceMapMatch = lua.match(
129+
/--# sourceMappingURL=data:application\/json;base64,([A-Za-z0-9+/=]+)/,
130+
);
131+
expect(inlineSourceMapMatch !== null && inlineSourceMapMatch !== undefined).toBe(true);
132+
133+
const inlineSourceMap = Buffer.from(inlineSourceMapMatch[1], "base64").toString();
134+
expect(sourceMap).toBe(inlineSourceMap);
135+
136+
expect(util.executeLua(lua)).toBe("foo");
137+
});
138+
112139
// Helper functions
113140

114141
function lineAndColumnOf(text: string, pattern: string): Position {

0 commit comments

Comments
 (0)