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

Function processImportedModules

test/fixtures/snapshot/typescript.js:118561–118615  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

118559 return host.getCanonicalFileName(fileName);
118560 }
118561 function processImportedModules(file) {
118562 var _a;
118563 collectExternalModuleReferences(file);
118564 if (file.imports.length || file.moduleAugmentations.length) {
118565 // Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
118566 var moduleNames = getModuleNames(file);
118567 var resolutions = resolveModuleNamesReusingOldState(moduleNames, file);
118568 ts.Debug.assert(resolutions.length === moduleNames.length);
118569 var optionsForFile = (useSourceOfProjectReferenceRedirect ? (_a = getRedirectReferenceForResolution(file)) === null || _a === void 0 ? void 0 : _a.commandLine.options : undefined) || options;
118570 for (var index = 0; index < moduleNames.length; index++) {
118571 var resolution = resolutions[index];
118572 ts.setResolvedModule(file, moduleNames[index], resolution, getModeForResolutionAtIndex(file, index));
118573 if (!resolution) {
118574 continue;
118575 }
118576 var isFromNodeModulesSearch = resolution.isExternalLibraryImport;
118577 var isJsFile = !ts.resolutionExtensionIsTSOrJson(resolution.extension);
118578 var isJsFileFromNodeModules = isFromNodeModulesSearch && isJsFile;
118579 var resolvedFileName = resolution.resolvedFileName;
118580 if (isFromNodeModulesSearch) {
118581 currentNodeModulesDepth++;
118582 }
118583 // add file to program only if:
118584 // - resolution was successful
118585 // - noResolve is falsy
118586 // - module name comes from the list of imports
118587 // - it's not a top level JavaScript module that exceeded the search max
118588 var elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModuleJsDepth;
118589 // Don't add the file if it has a bad extension (e.g. 'tsx' if we don't have '--allowJs')
118590 // This may still end up being an untyped module -- the file won't be included but imports will be allowed.
118591 var shouldAddFile = resolvedFileName
118592 && !getResolutionDiagnostic(optionsForFile, resolution)
118593 && !optionsForFile.noResolve
118594 && index < file.imports.length
118595 && !elideImport
118596 && !(isJsFile && !ts.getAllowJSCompilerOption(optionsForFile))
118597 && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 8388608 /* NodeFlags.JSDoc */));
118598 if (elideImport) {
118599 modulesWithElidedImports.set(file.path, true);
118600 }
118601 else if (shouldAddFile) {
118602 findSourceFile(resolvedFileName,
118603 /*isDefaultLib*/ false,
118604 /*ignoreNoDefaultLib*/ false, { kind: ts.FileIncludeKind.Import, file: file.path, index: index, }, resolution.packageId);
118605 }
118606 if (isFromNodeModulesSearch) {
118607 currentNodeModulesDepth--;
118608 }
118609 }
118610 }
118611 else {
118612 // no imports - drop cached module resolutions
118613 file.resolvedModules = undefined;
118614 }
118615 }
118616 function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) {
118617 var allFilesBelongToPath = true;
118618 var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory));

Callers 1

findSourceFileWorkerFunction · 0.85

Calls 9

getModuleNamesFunction · 0.85
getResolutionDiagnosticFunction · 0.85
findSourceFileFunction · 0.85
assertMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…