MCPcopy Index your code
hub / github.com/nodejs/node / getOriginalSource

Function getOriginalSource

lib/internal/source_map/source_map_cache.js:415–436  ·  view source on GitHub ↗

* Retrieve the original source code from the source map's `sources` list or disk. * @param {import('internal/source_map/source_map').SourceMap.payload} payload * @param {string} originalSourcePath - path or url of the original source * @returns {string | undefined} - the source content or undefin

(payload, originalSourcePath)

Source from the content-addressed store, hash-verified

413 * @returns {string | undefined} - the source content or undefined if file not found
414 */
415function getOriginalSource(payload, originalSourcePath) {
416 let source;
417 // payload.sources has been normalized to be an array of absolute urls.
418 const sourceContentIndex =
419 ArrayPrototypeIndexOf(payload.sources, originalSourcePath);
420 if (payload.sourcesContent?.[sourceContentIndex]) {
421 // First we check if the original source content was provided in the
422 // source map itself:
423 source = payload.sourcesContent[sourceContentIndex];
424 } else if (StringPrototypeStartsWith(originalSourcePath, 'file://')) {
425 // If no sourcesContent was found, attempt to load the original source
426 // from disk:
427 debug(`read source of ${originalSourcePath} from filesystem`);
428 const originalSourcePathNoScheme = fileURLToPath(originalSourcePath);
429 try {
430 source = readFileSync(originalSourcePathNoScheme, 'utf8');
431 } catch (err) {
432 debug(err);
433 }
434 }
435 return source;
436}
437
438/**
439 * Get the line of source in the source map.

Callers 1

getSourceLineFunction · 0.85

Calls 3

fileURLToPathFunction · 0.85
debugFunction · 0.50
readFileSyncFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…