Skip to content

Commit 2f17c63

Browse files
authored
Merge pull request #299 from cspotcode/fix-298
Fix 298
2 parents 6937282 + 5b6616d commit 2f17c63

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/source-map-consumer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ SourceMapConsumer.prototype.eachMapping =
144144

145145
var sourceRoot = this.sourceRoot;
146146
mappings.map(function (mapping) {
147-
var source = mapping.source === null ? null : this._sources.at(mapping.source);
148-
source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
147+
var source = null;
148+
if(mapping.source !== null) {
149+
source = this._sources.at(mapping.source);
150+
source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
151+
}
149152
return {
150153
source: source,
151154
generatedLine: mapping.generatedLine,

test/test-source-map-consumer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ exports['test eachMapping'] = function (assert) {
270270
map.eachMapping(function (mapping) {
271271
assert.ok(mapping.source === 'one.js' || mapping.source === 'two.js');
272272
});
273+
274+
map = new SourceMapConsumer(util.mapWithSourcelessMapping);
275+
map.eachMapping(function (mapping) {
276+
assert.ok(mapping.source === null || (typeof mapping.originalColumn === 'number' && typeof mapping.originalLine === 'number'));
277+
});
273278
};
274279

275280
exports['test eachMapping for indexed source maps'] = function(assert) {

test/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ exports.emptyMap = {
249249
sources: [],
250250
mappings: ''
251251
};
252+
exports.mapWithSourcelessMapping = {
253+
version: 3,
254+
file: 'example.js',
255+
names: [],
256+
sources: ['example.js'],
257+
mappings: 'AAgCA,C'
258+
};
252259

253260

254261
function assertMapping(generatedLine, generatedColumn, originalSource,

0 commit comments

Comments
 (0)