Skip to content

Commit

Permalink
prevent input source map mutation (#3781)
Browse files Browse the repository at this point in the history
fixes #3780
  • Loading branch information
alexlamsl authored Apr 15, 2020
1 parent c4d28e3 commit 6e9afdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/sourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ function SourceMap(options) {
if (options.orig) Object.keys(options.orig).forEach(function(name) {
var map = options.orig[name];
var indices = [ 0, 0, 1, 0, 0 ];
map.mappings = map.mappings.split(/;/).map(function(line) {
indices[0] = 0;
return line.split(/,/).map(function(segment) {
return indices.slice(0, vlq_decode(indices, segment));
});
});
options.orig[name] = {
names: map.names,
mappings: map.mappings.split(/;/).map(function(line) {
indices[0] = 0;
return line.split(/,/).map(function(segment) {
return indices.slice(0, vlq_decode(indices, segment));
});
}),
sources: map.sources,
};
if (!sources_content || !map.sourcesContent) return;
for (var i = 0; i < map.sources.length; i++) {
var content = map.sourcesContent[i];
Expand Down
6 changes: 6 additions & 0 deletions test/mocha/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ describe("sourcemaps", function() {
});

describe("input sourcemaps", function() {
it("Should not modify input source map", function() {
var orig = get_map();
var original = JSON.stringify(orig);
var map = prepare_map(orig);
assert.strictEqual(JSON.stringify(orig), original);
});
it("Should copy over original sourcesContent", function() {
var orig = get_map();
var map = prepare_map(orig);
Expand Down

0 comments on commit 6e9afdc

Please sign in to comment.