Skip to content

Commit

Permalink
Ensure null source is respected. (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirtitian authored Sep 8, 2024
1 parent 9403576 commit 0f58a3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ SourceMapConsumer.prototype.eachMapping =
for (var i = 0, n = mappings.length; i < n; i++) {
var mapping = mappings[i];
var source = mapping.source === null ? null : sources.at(mapping.source);
source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
if(source !== null) {
source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
}
boundCallback({
source: source,
generatedLine: mapping.generatedLine,
Expand Down Expand Up @@ -1142,7 +1144,9 @@ IndexedSourceMapConsumer.prototype._parseMappings =
var mapping = sectionMappings[j];

var source = section.consumer._sources.at(mapping.source);
source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
if(source !== null) {
source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
}
this._sources.add(source);
source = this._sources.indexOf(source);

Expand Down
15 changes: 15 additions & 0 deletions test/test-source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,3 +768,18 @@ exports['test numeric names #231'] = function (assert) {
assert.equal(map.names.length, 1, "Should have one name");
assert.equal(map.names[0], "8", "Should have the right name");
};

exports['test that we can create a generator from a source map with empty mappings'] = function (assert) {
var generator = new SourceMapGenerator();
generator.addMapping({
generated: { line: 1, column: 1 },
original: null,
source: null,
});
const originalMap = generator.toJSON();
const consumer = new SourceMapConsumer(originalMap);
const fromConsumer = SourceMapGenerator.fromSourceMap(consumer);
const fromSourceMap = fromConsumer.toJSON();
assert.ok(fromSourceMap, "Creating a generator from a map with only generated position did not throw");
assert.equal(fromSourceMap.mappings, originalMap.mappings);
}

0 comments on commit 0f58a3f

Please sign in to comment.