Skip to content

Commit 8ec2b86

Browse files
authored
fix: don't ignore source file when sourceContent contains null (#148)
1 parent 868948f commit 8ec2b86

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export default async function loader(input, inputMap) {
9494
let sourceContent;
9595

9696
const originalSourceContent =
97-
map.sourcesContent && typeof map.sourcesContent[i] !== "undefined"
97+
map.sourcesContent &&
98+
typeof map.sourcesContent[i] !== "undefined" &&
99+
map.sourcesContent[i] !== null
98100
? map.sourcesContent[i]
99101
: // eslint-disable-next-line no-undefined
100102
undefined;

test/__snapshots__/loader.test.js.snap

+26
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,32 @@ Object {
334334

335335
exports[`source-map-loader should process inlined sources: warnings 1`] = `Array []`;
336336

337+
exports[`source-map-loader should process null in sources content: css 1`] = `
338+
"with SourceMap
339+
// comment
340+
"
341+
`;
342+
343+
exports[`source-map-loader should process null in sources content: errors 1`] = `Array []`;
344+
345+
exports[`source-map-loader should process null in sources content: map 1`] = `
346+
Object {
347+
"file": "null-in-sources-content.js",
348+
"mappings": "AAAA",
349+
"sources": Array [
350+
"/test/fixtures/null-in-sources-content.txt - (normalized for test)",
351+
],
352+
"sourcesContent": Array [
353+
"with SourceMap
354+
// comment
355+
",
356+
],
357+
"version": 3,
358+
}
359+
`;
360+
361+
exports[`source-map-loader should process null in sources content: warnings 1`] = `Array []`;
362+
337363
exports[`source-map-loader should process percent-encoding path: css 1`] = `
338364
"with SourceMap
339365
// comment
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
with SourceMap
2+
// #sourceMappingURL=null-in-sources-content.js.map
3+
// comment

test/fixtures/null-in-sources-content.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
with SourceMap
2+
// comment

test/loader.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ describe("source-map-loader", () => {
107107
expect(getErrors(stats)).toMatchSnapshot("errors");
108108
});
109109

110+
it("should process null in sources content", async () => {
111+
const testId = "null-in-sources-content.js";
112+
const compiler = getCompiler(testId);
113+
const stats = await compile(compiler);
114+
const codeFromBundle = getCodeFromBundle(stats, compiler);
115+
const deps = stats.compilation.fileDependencies;
116+
117+
const dependencies = [
118+
path.resolve(__dirname, "fixtures", "null-in-sources-content.js.map"),
119+
];
120+
121+
dependencies.forEach((fixture) => {
122+
expect(deps.has(fixture)).toBe(true);
123+
});
124+
expect(codeFromBundle.map).toBeDefined();
125+
expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map");
126+
expect(codeFromBundle.css).toMatchSnapshot("css");
127+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
128+
expect(getErrors(stats)).toMatchSnapshot("errors");
129+
});
130+
110131
it("should reject http SourceMaps", async () => {
111132
const testId = "http-source-map.js";
112133
const compiler = getCompiler(testId);

0 commit comments

Comments
 (0)