Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(index): handle exception on loading invalid source maps (#65) #67

Merged
merged 2 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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