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

Function loadSource

lib/internal/modules/cjs/loader.js:1959–1987  ·  view source on GitHub ↗

* Get the source code of a module, using cached ones if it's cached. This is used * for TypeScript, JavaScript and JSON loading. * After this returns, mod[kFormat], mod[kModuleSource] and mod[kURL] will be set. * @param {Module} mod Module instance whose source is potentially already cached. * @

(mod, filename, formatFromNode)

Source from the content-addressed store, hash-verified

1957 * @returns {{source: string, format?: string}}
1958 */
1959function loadSource(mod, filename, formatFromNode) {
1960 if (mod[kFormat] === undefined) {
1961 mod[kFormat] = formatFromNode;
1962 }
1963 // If the module was loaded before, just return.
1964 if (mod[kModuleSource] !== undefined) {
1965 return { source: mod[kModuleSource], format: mod[kFormat] };
1966 }
1967
1968 // Fast path: no hooks, just load it and return.
1969 if (!loadHooks.length) {
1970 const source = defaultLoadImpl(filename, formatFromNode);
1971 return { source, format: formatFromNode };
1972 }
1973
1974 if (mod[kURL] === undefined) {
1975 mod[kURL] = convertCJSFilenameToURL(filename);
1976 }
1977
1978 const defaultLoad = getDefaultLoad(mod[kURL], filename);
1979 const loadResult = loadWithHooks(mod[kURL], mod[kFormat], /* importAttributes */ undefined,
1980 getCjsConditionsArray(), defaultLoad, validateLoadStrict);
1981 // Reset the module properties with load hook results.
1982 if (loadResult.format !== undefined) {
1983 mod[kFormat] = loadResult.format;
1984 }
1985 mod[kModuleSource] = loadResult.source;
1986 return { source: mod[kModuleSource], format: mod[kFormat] };
1987}
1988
1989function reconstructErrorStack(err, parentPath, parentSource) {
1990 const errLine = StringPrototypeSplit(

Callers 2

getRequireESMErrorFunction · 0.70
loader.jsFile · 0.70

Calls 5

defaultLoadImplFunction · 0.85
convertCJSFilenameToURLFunction · 0.85
getDefaultLoadFunction · 0.85
loadWithHooksFunction · 0.85
getCjsConditionsArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…