From 6e9afdc94fd51a827e9d9db51d650e15681866d3 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 15 Apr 2020 10:25:58 +0100 Subject: prevent input source map mutation (#3781) fixes #3780 --- lib/sourcemap.js | 16 ++++++++++------ test/mocha/sourcemaps.js | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/sourcemap.js b/lib/sourcemap.js index 232cfabd..25fbe3bf 100644 --- a/lib/sourcemap.js +++ b/lib/sourcemap.js @@ -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]; diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index f8e399ce..23698c57 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -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); -- cgit v1.2.3