Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null source content ignoring on processing source map #148

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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