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

Function tryReuseStructureFromOldProgram

test/fixtures/snapshot/typescript.js:117206–117413  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

117204 });
117205 }
117206 function tryReuseStructureFromOldProgram() {
117207 var _a;
117208 if (!oldProgram) {
117209 return 0 /* StructureIsReused.Not */;
117210 }
117211 // check properties that can affect structure of the program or module resolution strategy
117212 // if any of these properties has changed - structure cannot be reused
117213 var oldOptions = oldProgram.getCompilerOptions();
117214 if (ts.changesAffectModuleResolution(oldOptions, options)) {
117215 return 0 /* StructureIsReused.Not */;
117216 }
117217 // there is an old program, check if we can reuse its structure
117218 var oldRootNames = oldProgram.getRootFileNames();
117219 if (!ts.arrayIsEqualTo(oldRootNames, rootNames)) {
117220 return 0 /* StructureIsReused.Not */;
117221 }
117222 // Check if any referenced project tsconfig files are different
117223 if (!canReuseProjectReferences()) {
117224 return 0 /* StructureIsReused.Not */;
117225 }
117226 if (projectReferences) {
117227 resolvedProjectReferences = projectReferences.map(parseProjectReferenceConfigFile);
117228 }
117229 // check if program source files has changed in the way that can affect structure of the program
117230 var newSourceFiles = [];
117231 var modifiedSourceFiles = [];
117232 structureIsReused = 2 /* StructureIsReused.Completely */;
117233 // If the missing file paths are now present, it can change the progam structure,
117234 // and hence cant reuse the structure.
117235 // This is same as how we dont reuse the structure if one of the file from old program is now missing
117236 if (oldProgram.getMissingFilePaths().some(function (missingFilePath) { return host.fileExists(missingFilePath); })) {
117237 return 0 /* StructureIsReused.Not */;
117238 }
117239 var oldSourceFiles = oldProgram.getSourceFiles();
117240 var SeenPackageName;
117241 (function (SeenPackageName) {
117242 SeenPackageName[SeenPackageName["Exists"] = 0] = "Exists";
117243 SeenPackageName[SeenPackageName["Modified"] = 1] = "Modified";
117244 })(SeenPackageName || (SeenPackageName = {}));
117245 var seenPackageNames = new ts.Map();
117246 for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
117247 var oldSourceFile = oldSourceFiles_2[_i];
117248 var newSourceFile = host.getSourceFileByPath
117249 ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
117250 : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
117251 if (!newSourceFile) {
117252 return 0 /* StructureIsReused.Not */;
117253 }
117254 ts.Debug.assert(!newSourceFile.redirectInfo, "Host should not return a redirect source file from `getSourceFile`");
117255 var fileChanged = void 0;
117256 if (oldSourceFile.redirectInfo) {
117257 // We got `newSourceFile` by path, so it is actually for the unredirected file.
117258 // This lets us know if the unredirected file has changed. If it has we should break the redirect.
117259 if (newSourceFile !== oldSourceFile.redirectInfo.unredirected) {
117260 // Underlying file has changed. Might not redirect anymore. Must rebuild program.
117261 return 0 /* StructureIsReused.Not */;
117262 }
117263 fileChanged = false;

Callers 1

createProgramFunction · 0.85

Calls 15

getModuleNamesFunction · 0.85
someMethod · 0.80
assertMethod · 0.80
mapMethod · 0.65
hasMethod · 0.65
getMethod · 0.65
forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…