@@ -1095,7 +1095,6 @@ namespace ts {
1095
1095
1096
1096
// check if program source files has changed in the way that can affect structure of the program
1097
1097
const newSourceFiles : SourceFile [ ] = [ ] ;
1098
- const filePaths : Path [ ] = [ ] ;
1099
1098
const modifiedSourceFiles : { oldFile : SourceFile , newFile : SourceFile } [ ] = [ ] ;
1100
1099
oldProgram . structureIsReused = StructureIsReused . Completely ;
1101
1100
@@ -1148,7 +1147,6 @@ namespace ts {
1148
1147
newSourceFile . originalFileName = oldSourceFile . originalFileName ;
1149
1148
newSourceFile . resolvedPath = oldSourceFile . resolvedPath ;
1150
1149
newSourceFile . fileName = oldSourceFile . fileName ;
1151
- filePaths . push ( newSourceFile . path ) ;
1152
1150
1153
1151
const packageName = oldProgram . sourceFileToPackageName . get ( oldSourceFile . path ) ;
1154
1152
if ( packageName !== undefined ) {
@@ -1266,11 +1264,12 @@ namespace ts {
1266
1264
missingFilePaths = oldProgram . getMissingFilePaths ( ) ;
1267
1265
1268
1266
// update fileName -> file mapping
1269
- for ( let i = 0 ; i < newSourceFiles . length ; i ++ ) {
1270
- filesByName . set ( filePaths [ i ] , newSourceFiles [ i ] ) ;
1267
+ for ( const newSourceFile of newSourceFiles ) {
1268
+ const filePath = newSourceFile . path ;
1269
+ addFileToFilesByName ( newSourceFile , filePath , newSourceFile . resolvedPath ) ;
1271
1270
// Set the file as found during node modules search if it was found that way in old progra,
1272
- if ( oldProgram . isSourceFileFromExternalLibrary ( oldProgram . getSourceFileByPath ( filePaths [ i ] ) ! ) ) {
1273
- sourceFilesFoundSearchingNodeModules . set ( filePaths [ i ] , true ) ;
1271
+ if ( oldProgram . isSourceFileFromExternalLibrary ( oldProgram . getSourceFileByPath ( filePath ) ! ) ) {
1272
+ sourceFilesFoundSearchingNodeModules . set ( filePath , true ) ;
1274
1273
}
1275
1274
}
1276
1275
@@ -2113,7 +2112,7 @@ namespace ts {
2113
2112
return file ;
2114
2113
}
2115
2114
2116
- let redirectedPath : string | undefined ;
2115
+ let redirectedPath : Path | undefined ;
2117
2116
if ( refFile ) {
2118
2117
const redirect = getProjectReferenceRedirect ( fileName ) ;
2119
2118
if ( redirect ) {
@@ -2147,7 +2146,7 @@ namespace ts {
2147
2146
// Instead of creating a duplicate, just redirect to the existing one.
2148
2147
const dupFile = createRedirectSourceFile ( fileFromPackageId , file ! , fileName , path , toPath ( fileName ) , originalFileName ) ; // TODO: GH#18217
2149
2148
redirectTargetsMap . add ( fileFromPackageId . path , fileName ) ;
2150
- filesByName . set ( path , dupFile ) ;
2149
+ addFileToFilesByName ( dupFile , path , redirectedPath ) ;
2151
2150
sourceFileToPackageName . set ( path , packageId . name ) ;
2152
2151
processingOtherFiles ! . push ( dupFile ) ;
2153
2152
return dupFile ;
@@ -2158,11 +2157,7 @@ namespace ts {
2158
2157
sourceFileToPackageName . set ( path , packageId . name ) ;
2159
2158
}
2160
2159
}
2161
-
2162
- filesByName . set ( path , file ) ;
2163
- if ( redirectedPath ) {
2164
- filesByName . set ( redirectedPath , file ) ;
2165
- }
2160
+ addFileToFilesByName ( file , path , redirectedPath ) ;
2166
2161
2167
2162
if ( file ) {
2168
2163
sourceFilesFoundSearchingNodeModules . set ( path , currentNodeModulesDepth > 0 ) ;
@@ -2205,6 +2200,13 @@ namespace ts {
2205
2200
return file ;
2206
2201
}
2207
2202
2203
+ function addFileToFilesByName ( file : SourceFile | undefined , path : Path , redirectedPath : Path | undefined ) {
2204
+ filesByName . set ( path , file ) ;
2205
+ if ( redirectedPath ) {
2206
+ filesByName . set ( redirectedPath , file ) ;
2207
+ }
2208
+ }
2209
+
2208
2210
function getProjectReferenceRedirect ( fileName : string ) : string | undefined {
2209
2211
// Ignore dts or any of the non ts files
2210
2212
if ( ! resolvedProjectReferences || ! resolvedProjectReferences . length || fileExtensionIs ( fileName , Extension . Dts ) || ! fileExtensionIsOneOf ( fileName , supportedTSExtensions ) ) {
0 commit comments