Skip to content

Commit d0d00a6

Browse files
authored
Merge pull request #292 from timbell/additional-empty-mappings-fix
handle empty mappings in applySourceMap
2 parents ac518d2 + e51a5c6 commit d0d00a6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/source-map-generator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ SourceMapGenerator.prototype.applySourceMap =
197197
}
198198
// Applying the SourceMap can add and remove items from the sources and
199199
// the names array.
200-
var newSources = new ArraySet();
200+
var newSources = this._mappings.toArray().length > 0
201+
? new ArraySet()
202+
: this._sources;
201203
var newNames = new ArraySet();
202204

203205
// Find mappings for the "sourceFile"

test/test-source-map-generator.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,18 @@ exports['test applySourceMap with unexact match'] = function (assert) {
740740
util.assertEqualMaps(assert, map1.toJSON(), expectedMap.toJSON());
741741
};
742742

743+
exports['test applySourceMap with empty mappings'] = function (assert) {
744+
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMapEmptyMappings));
745+
generator.applySourceMap(new SourceMapConsumer(util.testMapEmptyMappings));
746+
util.assertEqualMaps(assert, generator.toJSON(), util.testMapEmptyMappings);
747+
};
748+
749+
exports['test applySourceMap with empty mappings and relative sources'] = function (assert) {
750+
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMapEmptyMappingsRelativeSources));
751+
generator.applySourceMap(new SourceMapConsumer(util.testMapEmptyMappingsRelativeSources));
752+
util.assertEqualMaps(assert, generator.toJSON(), util.testMapEmptyMappingsRelativeSources_generatedExpected);
753+
};
754+
743755
exports['test issue #192'] = function (assert) {
744756
var generator = new SourceMapGenerator();
745757
generator.addMapping({

0 commit comments

Comments
 (0)