Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit bef9a32

Browse files
committed
fix: generating empty inline sourcemaps
Fixes by lazily init `SourceMapGenerator`
1 parent 41b1abe commit bef9a32

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/swc/file.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export default async function ({
1818
file: string,
1919
...results: swc.Output[]
2020
): Promise<swc.Output> {
21-
const map = new SourceMapGenerator({
22-
file,
23-
sourceRoot: swcOptions.sourceRoot,
24-
});
21+
const initMap = () =>
22+
new SourceMapGenerator({
23+
file,
24+
sourceRoot: swcOptions.sourceRoot,
25+
});
26+
27+
let map: SourceMapGenerator | null = null;
2528

2629
let code = "";
2730
let offset = 0;
@@ -35,6 +38,11 @@ export default async function ({
3538

3639
consumer.eachMapping(mapping => {
3740
sources.add(mapping.source);
41+
42+
if (map == null) {
43+
map = initMap();
44+
}
45+
3846
map.addMapping({
3947
generated: {
4048
line: mapping.generatedLine + offset,
@@ -50,7 +58,7 @@ export default async function ({
5058

5159
sources.forEach(source => {
5260
const content = consumer.sourceContentFor(source, true);
53-
if (content !== null) {
61+
if (content !== null && map != null) {
5462
map.setSourceContent(source, content);
5563
}
5664
});

0 commit comments

Comments
 (0)