@@ -151,7 +151,8 @@ namespace ts {
151
151
const toImport = oldFromNew !== undefined
152
152
// If we're at the new location (file was already renamed), need to redo module resolution starting from the old location.
153
153
// TODO:GH#18217
154
- ? getSourceFileToImportFromResolved ( resolveModuleName ( importLiteral . text , oldImportFromPath , program . getCompilerOptions ( ) , host as ModuleResolutionHost ) , oldToNew )
154
+ ? getSourceFileToImportFromResolved ( resolveModuleName ( importLiteral . text , oldImportFromPath , program . getCompilerOptions ( ) , host as ModuleResolutionHost ) ,
155
+ oldToNew , allFiles )
155
156
: getSourceFileToImport ( importedModuleSymbol , importLiteral , sourceFile , program , host , oldToNew ) ;
156
157
157
158
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
@@ -192,11 +193,11 @@ namespace ts {
192
193
const resolved = host . resolveModuleNames
193
194
? host . getResolvedModuleWithFailedLookupLocationsFromCache && host . getResolvedModuleWithFailedLookupLocationsFromCache ( importLiteral . text , importingSourceFile . fileName )
194
195
: program . getResolvedModuleWithFailedLookupLocationsFromCache ( importLiteral . text , importingSourceFile . fileName ) ;
195
- return getSourceFileToImportFromResolved ( resolved , oldToNew ) ;
196
+ return getSourceFileToImportFromResolved ( resolved , oldToNew , program . getSourceFiles ( ) ) ;
196
197
}
197
198
}
198
199
199
- function getSourceFileToImportFromResolved ( resolved : ResolvedModuleWithFailedLookupLocations | undefined , oldToNew : PathUpdater ) : ToImport | undefined {
200
+ function getSourceFileToImportFromResolved ( resolved : ResolvedModuleWithFailedLookupLocations | undefined , oldToNew : PathUpdater , sourceFiles : readonly SourceFile [ ] ) : ToImport | undefined {
200
201
// Search through all locations looking for a moved file, and only then test already existing files.
201
202
// This is because if `a.ts` is compiled to `a.js` and `a.ts` is moved, we don't want to resolve anything to `a.js`, but to `a.ts`'s new location.
202
203
if ( ! resolved ) return undefined ;
@@ -207,13 +208,21 @@ namespace ts {
207
208
if ( result ) return result ;
208
209
}
209
210
210
- // Then failed lookups except package.json since we dont want to touch them (only included ts/js files)
211
- const result = forEach ( resolved . failedLookupLocations , tryChangeWithIgnoringPackageJson ) ;
211
+ // Then failed lookups that are in the list of sources
212
+ const result = forEach ( resolved . failedLookupLocations , tryChangeWithIgnoringPackageJsonExisting )
213
+ // Then failed lookups except package.json since we dont want to touch them (only included ts/js files)
214
+ || forEach ( resolved . failedLookupLocations , tryChangeWithIgnoringPackageJson ) ;
212
215
if ( result ) return result ;
213
216
214
217
// If nothing changed, then result is resolved module file thats not updated
215
218
return resolved . resolvedModule && { newFileName : resolved . resolvedModule . resolvedFileName , updated : false } ;
216
219
220
+ function tryChangeWithIgnoringPackageJsonExisting ( oldFileName : string ) {
221
+ const newFileName = oldToNew ( oldFileName ) ;
222
+ return newFileName && find ( sourceFiles , src => src . fileName === newFileName )
223
+ ? tryChangeWithIgnoringPackageJson ( oldFileName ) : undefined ;
224
+ }
225
+
217
226
function tryChangeWithIgnoringPackageJson ( oldFileName : string ) {
218
227
return ! endsWith ( oldFileName , "/package.json" ) ? tryChange ( oldFileName ) : undefined ;
219
228
}
0 commit comments