From a7ebc2f9fe8537369926f6aab9b77062dcf4b8d9 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 18 Jun 2019 20:16:20 +0200 Subject: [PATCH 1/3] when `sourceContentFor(aSource, nullOnMissing=false)` shouldn't this situation also throw an exception? In the other situation, where this API might also produce a NULL return, an exception *is* thrown instead, so this looks to me like the more consistent behaviour. --- lib/source-map-consumer.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/source-map-consumer.js b/lib/source-map-consumer.js index 9b68e393..63069a1c 100644 --- a/lib/source-map-consumer.js +++ b/lib/source-map-consumer.js @@ -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); From b974ff23309d316ffda169f11b684e9cc7468af0 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 18 Jun 2019 20:37:54 +0200 Subject: [PATCH 2/3] allow the sourceMapGenerator code to also enjoy the `nullOrMissing` argument/option for the `consumer.sourceContentFor()` API. --- lib/source-map-generator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/source-map-generator.js b/lib/source-map-generator.js index 8111e061..6851701b 100644 --- a/lib/source-map-generator.js +++ b/lib/source-map-generator.js @@ -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); } @@ -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); From d2c33d1c9a38f69e4448bdae4e9448cb00c7a3eb Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 18 Jun 2019 20:48:15 +0200 Subject: [PATCH 3/3] also use the `nullOrNothing` option/argument in the lib/source-node.js code to restore intended behaviour. All tests pass. --- lib/source-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/source-node.js b/lib/source-node.js index 8a7a157e..8f92c0a1 100644 --- a/lib/source-node.js +++ b/lib/source-node.js @@ -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);