Skip to content

Commit 04cf08d

Browse files
committed
Ensure a consistent return value for sourceContentFor
The sourceContentFor function was previously returning null when it should have returned an exception when the source content was not provided.
1 parent 8cb3ee5 commit 04cf08d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Diff for: lib/source-map-consumer.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,15 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
522522

523523
/**
524524
* Returns the original source content. The only argument is the url of the
525-
* original source file. Returns null if no original source content is
526-
* available.
525+
* original source file.
527526
*/
528527
sourceContentFor(aSource, nullOnMissing) {
529528
if (!this.sourcesContent) {
530-
return null;
529+
if (nullOnMissing) {
530+
return null;
531+
}
532+
533+
throw new Error('"' + aSource + '" is not in the SourceMap.');
531534
}
532535

533536
const index = this._findSourceIndex(aSource);
@@ -822,8 +825,7 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
822825

823826
/**
824827
* Returns the original source content. The only argument is the url of the
825-
* original source file. Returns null if no original source content is
826-
* available.
828+
* original source file.
827829
*/
828830
sourceContentFor(aSource, nullOnMissing) {
829831
for (let i = 0; i < this._sections.length; i++) {

Diff for: lib/source-map-generator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SourceMapGenerator {
7979
generator._sources.add(sourceRelative);
8080
}
8181

82-
const content = aSourceMapConsumer.sourceContentFor(sourceFile);
82+
const content = aSourceMapConsumer.sourceContentFor(sourceFile, true);
8383
if (content != null) {
8484
generator.setSourceContent(sourceFile, content);
8585
}
@@ -238,7 +238,7 @@ class SourceMapGenerator {
238238

239239
// Copy sourcesContents of applied map.
240240
aSourceMapConsumer.sources.forEach(function(srcFile) {
241-
const content = aSourceMapConsumer.sourceContentFor(srcFile);
241+
const content = aSourceMapConsumer.sourceContentFor(srcFile, true);
242242
if (content != null) {
243243
if (aSourceMapPath != null) {
244244
srcFile = util.join(aSourceMapPath, srcFile);

Diff for: lib/source-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class SourceNode {
137137

138138
// Copy sourcesContent into SourceNode
139139
aSourceMapConsumer.sources.forEach(function(sourceFile) {
140-
const content = aSourceMapConsumer.sourceContentFor(sourceFile);
140+
const content = aSourceMapConsumer.sourceContentFor(sourceFile, true);
141141
if (content != null) {
142142
if (aRelativePath != null) {
143143
sourceFile = util.join(aRelativePath, sourceFile);

0 commit comments

Comments
 (0)