Skip to content

Commit d08bc2f

Browse files
committed
Implementing fix and test for case when we have multiple sources but mapping refers to the single source only.
1 parent 0f1607c commit d08bc2f

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/source-map-generator.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,13 @@ SourceMapGenerator.fromSourceMap =
7272
generator.addMapping(newMapping);
7373
});
7474
aSourceMapConsumer.sources.forEach(function (sourceFile) {
75-
if (aSourceMapConsumer._mappings === '') {
76-
var sourceRelative = sourceFile;
77-
if (sourceRoot !== null) {
78-
sourceRelative = util.relative(sourceRoot, sourceFile);
79-
}
75+
var sourceRelative = sourceFile;
76+
if (sourceRoot !== null) {
77+
sourceRelative = util.relative(sourceRoot, sourceFile);
78+
}
8079

81-
if (!generator._sources.has(sourceRelative)) {
82-
generator._sources.add(sourceRelative);
83-
}
80+
if (!generator._sources.has(sourceRelative)) {
81+
generator._sources.add(sourceRelative);
8482
}
8583

8684
var content = aSourceMapConsumer.sourceContentFor(sourceFile);

test/test-source-map-generator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ exports['test .fromSourceMap with empty mappings and relative sources'] = functi
270270
util.assertEqualMaps(assert, map.toJSON(), util.testMapEmptyMappingsRelativeSources_generatedExpected);
271271
};
272272

273+
exports['test .fromSourceMap with multiple sources where mappings refers only to single source'] = function (assert) {
274+
var map = SourceMapGenerator.fromSourceMap(
275+
new SourceMapConsumer(util.testMapMultiSourcesMappingRefersSingleSourceOnly));
276+
util.assertEqualMaps(assert, map.toJSON(), util.testMapMultiSourcesMappingRefersSingleSourceOnly);
277+
};
278+
273279
exports['test applySourceMap'] = function (assert) {
274280
var node = new SourceNode(null, null, null, [
275281
new SourceNode(2, 0, 'fileX', 'lineX2\n'),

test/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ exports.testMapEmptyMappingsRelativeSources_generatedExpected = {
9595
sourceRoot: '/the/root',
9696
mappings: ''
9797
};
98+
exports.testMapMultiSourcesMappingRefersSingleSourceOnly = {
99+
version: 3,
100+
file: 'min.js',
101+
names: ['bar', 'baz'],
102+
sources: ['one.js', 'withoutMappings.js'],
103+
sourceRoot: '',
104+
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID'
105+
};
98106
// This mapping is identical to above, but uses the indexed format instead.
99107
exports.indexedTestMap = {
100108
version: 3,

0 commit comments

Comments
 (0)