Skip to content

Commit

Permalink
fix(index): handle exception on loading invalid source maps (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
fimius23 authored and michael-ciniawsky committed Aug 14, 2018
1 parent a0b84d4 commit 78ad469
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ module.exports = function(input, inputMap) {
emitWarning("Cannot open SourceMap '" + result + "': " + err);
return untouched();
}
processMap(JSON.parse(content), path.dirname(result), callback);
var map;
try {
map = JSON.parse(content);
} catch (e) {
emitWarning("Cannot parse SourceMap '" + url + "': " + e);
return untouched();
}
processMap(map, path.dirname(result), callback);
});
}.bind(this));
return;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/invalid-source-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
with SourceMap
//#sourceMappingURL=invalid-source-map.map
// comment
1 change: 1 addition & 0 deletions test/fixtures/invalid-source-map.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ describe("source-map-loader", function() {
done();
});
});
it("should warn on invalid SourceMap", function (done) {
execLoader(path.join(__dirname, "fixtures", "invalid-source-map.js"), function (err, res, map, deps, warns) {
should.equal(err, null);
warns.should.matchEach(
new RegExp("Cannot parse SourceMap 'invalid-source-map.map': SyntaxError: Unexpected string in JSON at position 102")
);
should.equal(res, "with SourceMap\n//#sourceMappingURL=invalid-source-map.map\n// comment");
should.equal(map, null);
deps.should.be.eql([
path.join(__dirname, "fixtures", "invalid-source-map.map")
]);
done();
});
});
it("should warn on missing SourceMap", function(done) {
execLoader(path.join(__dirname, "fixtures", "missing-source-map.js"), function(err, res, map, deps, warns) {
should.equal(err, null);
Expand Down

0 comments on commit 78ad469

Please sign in to comment.