Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export default async function loader(input, inputMap) {
let sourceContent;

const originalSourceContent =
map.sourcesContent && typeof map.sourcesContent[i] !== "undefined"
map.sourcesContent &&
typeof map.sourcesContent[i] !== "undefined" &&
map.sourcesContent[i] !== null
? map.sourcesContent[i]
: // eslint-disable-next-line no-undefined
undefined;
Expand Down
26 changes: 26 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,32 @@ Object {

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

exports[`source-map-loader should process null in sources content: css 1`] = `
"with SourceMap
// comment
"
`;

exports[`source-map-loader should process null in sources content: errors 1`] = `Array []`;

exports[`source-map-loader should process null in sources content: map 1`] = `
Object {
"file": "null-in-sources-content.js",
"mappings": "AAAA",
"sources": Array [
"/test/fixtures/null-in-sources-content.txt - (normalized for test)",
],
"sourcesContent": Array [
"with SourceMap
// comment
",
],
"version": 3,
}
`;

exports[`source-map-loader should process null in sources content: warnings 1`] = `Array []`;

exports[`source-map-loader should process percent-encoding path: css 1`] = `
"with SourceMap
// comment
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/null-in-sources-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
with SourceMap
// #sourceMappingURL=null-in-sources-content.js.map
// comment
1 change: 1 addition & 0 deletions test/fixtures/null-in-sources-content.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/fixtures/null-in-sources-content.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
with SourceMap
// comment
21 changes: 21 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ describe("source-map-loader", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should process null in sources content", async () => {
const testId = "null-in-sources-content.js";
const compiler = getCompiler(testId);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const deps = stats.compilation.fileDependencies;

const dependencies = [
path.resolve(__dirname, "fixtures", "null-in-sources-content.js.map"),
];

dependencies.forEach((fixture) => {
expect(deps.has(fixture)).toBe(true);
});
expect(codeFromBundle.map).toBeDefined();
expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map");
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should reject http SourceMaps", async () => {
const testId = "http-source-map.js";
const compiler = getCompiler(testId);
Expand Down