Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sourceContentFor(aSource, nullOnMissing=false) should NEVER return NULL, but throw an exception instead #398

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
*/
sourceContentFor(aSource, nullOnMissing) {
if (!this.sourcesContent) {
return null;
if (nullOnMissing) {
return null;
}

throw new Error('"' + aSource + '" is not in the SourceMap.');
}

const index = this._findSourceIndex(aSource);
Expand Down
4 changes: 2 additions & 2 deletions lib/source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SourceMapGenerator {
generator._sources.add(sourceRelative);
}

const content = aSourceMapConsumer.sourceContentFor(sourceFile);
const content = aSourceMapConsumer.sourceContentFor(sourceFile, true);
if (content != null) {
generator.setSourceContent(sourceFile, content);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ class SourceMapGenerator {

// Copy sourcesContents of applied map.
aSourceMapConsumer.sources.forEach(function(srcFile) {
const content = aSourceMapConsumer.sourceContentFor(srcFile);
const content = aSourceMapConsumer.sourceContentFor(srcFile, true);
if (content != null) {
if (aSourceMapPath != null) {
srcFile = util.join(aSourceMapPath, srcFile);
Expand Down
2 changes: 1 addition & 1 deletion lib/source-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SourceNode {

// Copy sourcesContent into SourceNode
aSourceMapConsumer.sources.forEach(function(sourceFile) {
const content = aSourceMapConsumer.sourceContentFor(sourceFile);
const content = aSourceMapConsumer.sourceContentFor(sourceFile, true);
if (content != null) {
if (aRelativePath != null) {
sourceFile = util.join(aRelativePath, sourceFile);
Expand Down