Skip to content

Commit

Permalink
fix: don't ignore source file when sourceContent contains null (#148
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ilgonmic committed May 17, 2021
1 parent 868948f commit 8ec2b86
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
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
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
@@ -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
@@ -0,0 +1,2 @@
with SourceMap
// comment
21 changes: 21 additions & 0 deletions test/loader.test.js
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

0 comments on commit 8ec2b86

Please sign in to comment.