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

Function resolveModuleNamesReusingOldState

test/fixtures/snapshot/typescript.js:117053–117185  ·  view source on GitHub ↗
(moduleNames, file)

Source from the content-addressed store, hash-verified

117051 return classifiableNames;
117052 }
117053 function resolveModuleNamesReusingOldState(moduleNames, file) {
117054 if (structureIsReused === 0 /* StructureIsReused.Not */ && !file.ambientModuleNames.length) {
117055 // If the old program state does not permit reusing resolutions and `file` does not contain locally defined ambient modules,
117056 // the best we can do is fallback to the default logic.
117057 return resolveModuleNamesWorker(moduleNames, file, /*reusedNames*/ undefined);
117058 }
117059 var oldSourceFile = oldProgram && oldProgram.getSourceFile(file.fileName);
117060 if (oldSourceFile !== file && file.resolvedModules) {
117061 // `file` was created for the new program.
117062 //
117063 // We only set `file.resolvedModules` via work from the current function,
117064 // so it is defined iff we already called the current function on `file`.
117065 // That call happened no later than the creation of the `file` object,
117066 // which per above occurred during the current program creation.
117067 // Since we assume the filesystem does not change during program creation,
117068 // it is safe to reuse resolutions from the earlier call.
117069 var result_14 = [];
117070 var i = 0;
117071 for (var _i = 0, moduleNames_1 = moduleNames; _i < moduleNames_1.length; _i++) {
117072 var moduleName = moduleNames_1[_i];
117073 var resolvedModule = file.resolvedModules.get(moduleName, getModeForResolutionAtIndex(file, i));
117074 i++;
117075 result_14.push(resolvedModule);
117076 }
117077 return result_14;
117078 }
117079 // At this point, we know at least one of the following hold:
117080 // - file has local declarations for ambient modules
117081 // - old program state is available
117082 // With this information, we can infer some module resolutions without performing resolution.
117083 /** An ordered list of module names for which we cannot recover the resolution. */
117084 var unknownModuleNames;
117085 /**
117086 * The indexing of elements in this list matches that of `moduleNames`.
117087 *
117088 * Before combining results, result[i] is in one of the following states:
117089 * * undefined: needs to be recomputed,
117090 * * predictedToResolveToAmbientModuleMarker: known to be an ambient module.
117091 * Needs to be reset to undefined before returning,
117092 * * ResolvedModuleFull instance: can be reused.
117093 */
117094 var result;
117095 var reusedNames;
117096 /** A transient placeholder used to mark predicted resolution in the result list. */
117097 var predictedToResolveToAmbientModuleMarker = {};
117098 for (var i = 0; i < moduleNames.length; i++) {
117099 var moduleName = moduleNames[i];
117100 // If the source file is unchanged and doesnt have invalidated resolution, reuse the module resolutions
117101 if (file === oldSourceFile && !hasInvalidatedResolution(oldSourceFile.path)) {
117102 var oldResolvedModule = ts.getResolvedModule(oldSourceFile, moduleName, getModeForResolutionAtIndex(oldSourceFile, i));
117103 if (oldResolvedModule) {
117104 if (ts.isTraceEnabled(options, host)) {
117105 ts.trace(host, oldResolvedModule.packageId ?
117106 ts.Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2_with_Package_ID_3 :
117107 ts.Diagnostics.Reusing_resolution_of_module_0_from_1_of_old_program_it_was_successfully_resolved_to_2, moduleName, ts.getNormalizedAbsolutePath(file.originalFileName, currentDirectory), oldResolvedModule.resolvedFileName, oldResolvedModule.packageId && ts.packageIdToString(oldResolvedModule.packageId));
117108 }
117109 (result || (result = new Array(moduleNames.length)))[i] = oldResolvedModule;
117110 (reusedNames || (reusedNames = [])).push(moduleName);

Callers 2

processImportedModulesFunction · 0.85

Calls 8

resolveModuleNamesWorkerFunction · 0.85
assertMethod · 0.80
getMethod · 0.65
pushMethod · 0.45
traceMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…