From 0876dbad9e58954726c92a3e2024cdc8972f28e1 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Mon, 17 May 2021 14:22:47 +0300 Subject: [PATCH 1/2] fix: consider null source content as mark to not skip reading --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index d3fe4a6..fa03809 100644 --- a/src/index.js +++ b/src/index.js @@ -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; From e22959c709ec2389c3cb2b98542a2e71988164c3 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Mon, 17 May 2021 14:52:25 +0300 Subject: [PATCH 2/2] test: add test on considering null source content as mark to not skip reading --- test/__snapshots__/loader.test.js.snap | 26 ++++++++++++++++++++ test/fixtures/null-in-sources-content.js | 3 +++ test/fixtures/null-in-sources-content.js.map | 1 + test/fixtures/null-in-sources-content.txt | 2 ++ test/loader.test.js | 21 ++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 test/fixtures/null-in-sources-content.js create mode 100644 test/fixtures/null-in-sources-content.js.map create mode 100644 test/fixtures/null-in-sources-content.txt diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index ef9ec67..3ba1991 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -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 diff --git a/test/fixtures/null-in-sources-content.js b/test/fixtures/null-in-sources-content.js new file mode 100644 index 0000000..1f007b5 --- /dev/null +++ b/test/fixtures/null-in-sources-content.js @@ -0,0 +1,3 @@ +with SourceMap +// #sourceMappingURL=null-in-sources-content.js.map +// comment diff --git a/test/fixtures/null-in-sources-content.js.map b/test/fixtures/null-in-sources-content.js.map new file mode 100644 index 0000000..d51134b --- /dev/null +++ b/test/fixtures/null-in-sources-content.js.map @@ -0,0 +1 @@ +{"version":3,"file":"null-in-sources-content.js","sources":["null-in-sources-content.txt"],"sourcesContent":[null],"mappings":"AAAA"} diff --git a/test/fixtures/null-in-sources-content.txt b/test/fixtures/null-in-sources-content.txt new file mode 100644 index 0000000..345c125 --- /dev/null +++ b/test/fixtures/null-in-sources-content.txt @@ -0,0 +1,2 @@ +with SourceMap +// comment diff --git a/test/loader.test.js b/test/loader.test.js index f484636..44d4927 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -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);