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

Commit dbebb3b

Browse files
evilebottnawijoshwiens
authored andcommitted
fix: improve isSouceMap check (#284)
1 parent 39ed7c7 commit dbebb3b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class UglifyJsPlugin {
149149
} else {
150150
inputSourceMap = map;
151151
compilation.warnings.push(
152-
new Error(`${file} contain invalid source map`),
152+
new Error(`${file} contains invalid source map`),
153153
);
154154
}
155155
} else {

src/utils/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function isSourceMap(input) {
44
return Boolean(input &&
55
input.version &&
66
input.sources &&
7-
input.names &&
8-
input.mappings);
7+
Array.isArray(input.sources) &&
8+
typeof input.mappings === 'string');
99
}
1010

1111
export default {

test/__snapshots__/source-map-options.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`when options.sourceMap true and options.parallel true compilation handl
44

55
exports[`when options.sourceMap true and options.parallel true compilation handler when called optimize-chunk-assets handler only calls callback once: warnings 1`] = `
66
Array [
7-
[Error: test4.js contain invalid source map],
7+
[Error: test4.js contains invalid source map],
88
]
99
`;
1010

@@ -204,7 +204,7 @@ exports[`when options.sourceMap true compilation handler when called optimize-ch
204204

205205
exports[`when options.sourceMap true compilation handler when called optimize-chunk-assets handler only calls callback once: warnings 1`] = `
206206
Array [
207-
[Error: test4.js contain invalid source map],
207+
[Error: test4.js contains invalid source map],
208208
]
209209
`;
210210

test/utils/index.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ describe('utils', () => {
1010
sourceRoot: 'http://example.com/www/js/',
1111
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA',
1212
};
13+
const emptyRawSourceMap = {
14+
version: 3,
15+
sources: [],
16+
mappings: '',
17+
};
1318

1419
expect(utils.isSourceMap(null)).toBe(false);
1520
expect(utils.isSourceMap()).toBe(false);
1621
expect(utils.isSourceMap({})).toBe(false);
1722
expect(utils.isSourceMap([])).toBe(false);
1823
expect(utils.isSourceMap('foo')).toBe(false);
24+
expect(utils.isSourceMap({ version: 3 })).toBe(false);
25+
expect(utils.isSourceMap({ sources: '' })).toBe(false);
26+
expect(utils.isSourceMap({ mappings: [] })).toBe(false);
27+
expect(utils.isSourceMap({ version: 3, sources: '' })).toBe(false);
28+
expect(utils.isSourceMap({ version: 3, mappings: [] })).toBe(false);
29+
expect(utils.isSourceMap({ sources: '', mappings: [] })).toBe(false);
30+
expect(utils.isSourceMap({ version: 3, sources: '', mappings: [] })).toBe(false);
1931
expect(utils.isSourceMap(rawSourceMap)).toBe(true);
32+
expect(utils.isSourceMap(emptyRawSourceMap)).toBe(true);
2033
});
2134
});

0 commit comments

Comments
 (0)