diff --git a/src/index.js b/src/index.js index 3104e0b2..a604dc19 100644 --- a/src/index.js +++ b/src/index.js @@ -149,7 +149,7 @@ class UglifyJsPlugin { } else { inputSourceMap = map; compilation.warnings.push( - new Error(`${file} contain invalid source map`), + new Error(`${file} contains invalid source map`), ); } } else { diff --git a/src/utils/index.js b/src/utils/index.js index 37b63c9f..68ff51eb 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -4,8 +4,8 @@ function isSourceMap(input) { return Boolean(input && input.version && input.sources && - input.names && - input.mappings); + Array.isArray(input.sources) && + typeof input.mappings === 'string'); } export default { diff --git a/test/__snapshots__/source-map-options.test.js.snap b/test/__snapshots__/source-map-options.test.js.snap index b750e4b0..ad1cdd6f 100644 --- a/test/__snapshots__/source-map-options.test.js.snap +++ b/test/__snapshots__/source-map-options.test.js.snap @@ -4,7 +4,7 @@ exports[`when options.sourceMap true and options.parallel true compilation handl exports[`when options.sourceMap true and options.parallel true compilation handler when called optimize-chunk-assets handler only calls callback once: warnings 1`] = ` Array [ - [Error: test4.js contain invalid source map], + [Error: test4.js contains invalid source map], ] `; @@ -204,7 +204,7 @@ exports[`when options.sourceMap true compilation handler when called optimize-ch exports[`when options.sourceMap true compilation handler when called optimize-chunk-assets handler only calls callback once: warnings 1`] = ` Array [ - [Error: test4.js contain invalid source map], + [Error: test4.js contains invalid source map], ] `; diff --git a/test/utils/index.test.js b/test/utils/index.test.js index 3899b084..3a27a19d 100644 --- a/test/utils/index.test.js +++ b/test/utils/index.test.js @@ -10,12 +10,25 @@ describe('utils', () => { sourceRoot: 'http://example.com/www/js/', mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA', }; + const emptyRawSourceMap = { + version: 3, + sources: [], + mappings: '', + }; expect(utils.isSourceMap(null)).toBe(false); expect(utils.isSourceMap()).toBe(false); expect(utils.isSourceMap({})).toBe(false); expect(utils.isSourceMap([])).toBe(false); expect(utils.isSourceMap('foo')).toBe(false); + expect(utils.isSourceMap({ version: 3 })).toBe(false); + expect(utils.isSourceMap({ sources: '' })).toBe(false); + expect(utils.isSourceMap({ mappings: [] })).toBe(false); + expect(utils.isSourceMap({ version: 3, sources: '' })).toBe(false); + expect(utils.isSourceMap({ version: 3, mappings: [] })).toBe(false); + expect(utils.isSourceMap({ sources: '', mappings: [] })).toBe(false); + expect(utils.isSourceMap({ version: 3, sources: '', mappings: [] })).toBe(false); expect(utils.isSourceMap(rawSourceMap)).toBe(true); + expect(utils.isSourceMap(emptyRawSourceMap)).toBe(true); }); });