Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
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