lib: codify findSourceMap return value when not found

Return `undefined` when no source map is found for the given filename on
`findSourceMap`.

PR-URL: https://github.com/nodejs/node/pull/44397
Fixes: https://github.com/nodejs/node/issues/44391
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Chengzhong Wu 2022-08-28 07:13:53 +08:00 committed by GitHub
parent 808fe9828d
commit 72df448d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -162,7 +162,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.

View File

@ -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 {

View File

@ -297,7 +297,7 @@ function findSourceMap(sourceURL) {
if (sourceMap && sourceMap.data) {
return new SourceMap(sourceMap.data);
}
return null;
return undefined;
}
module.exports = {

View File

@ -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.
{