Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
fix: improve isSouceMap check (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and joshwiens committed May 2, 2018
1 parent 39ed7c7 commit dbebb3b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/source-map-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]
`;

Expand Down Expand Up @@ -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],
]
`;

Expand Down
13 changes: 13 additions & 0 deletions test/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit dbebb3b

Please sign in to comment.