Skip to content

Commit b8f08e5

Browse files
legendecasRafaelGSS
authored andcommitted
lib: codify findSourceMap return value when not found
Return `undefined` when no source map is found for the given filename on `findSourceMap`. PR-URL: #44397 Fixes: #44391 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent cef30f9 commit b8f08e5

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

doc/api/module.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ added:
160160
-->
161161
162162
* `path` {string}
163-
* Returns: {module.SourceMap}
163+
* Returns: {module.SourceMap|undefined} Returns `module.SourceMap` if a source
164+
map is found, `undefined` otherwise.
164165
165166
`path` is the resolved path for the file for which a corresponding source map
166167
should be fetched.

lib/internal/source_map/prepare_stack_trace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function getOriginalSource(payload, originalSourcePath) {
195195

196196
function getSourceMapErrorSource(fileName, lineNumber, columnNumber) {
197197
const sm = findSourceMap(fileName);
198-
if (sm === null) {
198+
if (sm === undefined) {
199199
return;
200200
}
201201
const {

lib/internal/source_map/source_map_cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function findSourceMap(sourceURL) {
297297
if (sourceMap && sourceMap.data) {
298298
return new SourceMap(sourceMap.data);
299299
}
300-
return null;
300+
return undefined;
301301
}
302302

303303
module.exports = {

test/parallel/test-source-map-api.js

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ const { readFileSync } = require('fs');
2121
);
2222
}
2323

24+
// `findSourceMap()` should return undefined when no source map is found.
25+
{
26+
const files = [
27+
__filename,
28+
'',
29+
'invalid-file',
30+
];
31+
for (const file of files) {
32+
const sourceMap = findSourceMap(file);
33+
assert.strictEqual(sourceMap, undefined);
34+
}
35+
}
36+
2437
// findSourceMap() can lookup source-maps based on URIs, in the
2538
// non-exceptional case.
2639
{

0 commit comments

Comments
 (0)