Skip to content

Commit

Permalink
lib: codify findSourceMap return value when not found
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
legendecas authored and RafaelGSS committed Sep 5, 2022
1 parent cef30f9 commit b8f08e5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ added:
-->
* `path` {string}
* Returns: {module.SourceMap}
* Returns: {module.SourceMap|undefined} Returns `module.SourceMap` if a source
map is found, `undefined` otherwise.
`path` is the resolved path for the file for which a corresponding source map
should be fetched.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/source_map/prepare_stack_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function getOriginalSource(payload, originalSourcePath) {

function getSourceMapErrorSource(fileName, lineNumber, columnNumber) {
const sm = findSourceMap(fileName);
if (sm === null) {
if (sm === undefined) {
return;
}
const {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/source_map/source_map_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function findSourceMap(sourceURL) {
if (sourceMap && sourceMap.data) {
return new SourceMap(sourceMap.data);
}
return null;
return undefined;
}

module.exports = {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-source-map-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ const { readFileSync } = require('fs');
);
}

// `findSourceMap()` should return undefined when no source map is found.
{
const files = [
__filename,
'',
'invalid-file',
];
for (const file of files) {
const sourceMap = findSourceMap(file);
assert.strictEqual(sourceMap, undefined);
}
}

// findSourceMap() can lookup source-maps based on URIs, in the
// non-exceptional case.
{
Expand Down

0 comments on commit b8f08e5

Please sign in to comment.