* 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)
| 1957 | * @returns {{source: string, format?: string}} |
| 1958 | */ |
| 1959 | function 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 | |
| 1989 | function reconstructErrorStack(err, parentPath, parentSource) { |
| 1990 | const errLine = StringPrototypeSplit( |
no test coverage detected
searching dependent graphs…