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 <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy