@@ -248,6 +248,7 @@ namespace ts {
248248 perDirectoryCacheWithRedirects : CacheWithRedirects < Map < T > > ,
249249 loader : ( name : string , containingFile : string , options : CompilerOptions , host : ModuleResolutionHost , redirectedReference ?: ResolvedProjectReference ) => T ,
250250 getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ,
251+ shouldRetryResolution : ( t : T ) => boolean ,
251252 reusedNames : ReadonlyArray < string > | undefined ,
252253 logChanges : boolean ) : ( R | undefined ) [ ] {
253254
@@ -260,7 +261,7 @@ namespace ts {
260261 perDirectoryResolution = createMap ( ) ;
261262 perDirectoryCache . set ( dirPath , perDirectoryResolution ) ;
262263 }
263- const resolvedModules : R [ ] = [ ] ;
264+ const resolvedModules : ( R | undefined ) [ ] = [ ] ;
264265 const compilerOptions = resolutionHost . getCompilationSettings ( ) ;
265266 const hasInvalidatedNonRelativeUnresolvedImport = logChanges && isFileWithInvalidatedNonRelativeUnresolvedImports ( path ) ;
266267
@@ -278,7 +279,7 @@ namespace ts {
278279 if ( ! seenNamesInFile . has ( name ) &&
279280 allFilesHaveInvalidatedResolution || unmatchedRedirects || ! resolution || resolution . isInvalidated ||
280281 // If the name is unresolved import that was invalidated, recalculate
281- ( hasInvalidatedNonRelativeUnresolvedImport && ! isExternalModuleNameRelative ( name ) && ! getResolutionWithResolvedFileName ( resolution ) ) ) {
282+ ( hasInvalidatedNonRelativeUnresolvedImport && ! isExternalModuleNameRelative ( name ) && shouldRetryResolution ( resolution ) ) ) {
282283 const existingResolution = resolution ;
283284 const resolutionInDirectory = perDirectoryResolution . get ( name ) ;
284285 if ( resolutionInDirectory ) {
@@ -302,7 +303,7 @@ namespace ts {
302303 }
303304 Debug . assert ( resolution !== undefined && ! resolution . isInvalidated ) ;
304305 seenNamesInFile . set ( name , true ) ;
305- resolvedModules . push ( getResolutionWithResolvedFileName ( resolution ) ! ) ; // TODO: GH#18217
306+ resolvedModules . push ( getResolutionWithResolvedFileName ( resolution ) ) ;
306307 }
307308
308309 // Stop watching and remove the unused name
@@ -339,6 +340,7 @@ namespace ts {
339340 typeDirectiveNames , containingFile , redirectedReference ,
340341 resolvedTypeReferenceDirectives , perDirectoryResolvedTypeReferenceDirectives ,
341342 resolveTypeReferenceDirective , getResolvedTypeReferenceDirective ,
343+ /*shouldRetryResolution*/ resolution => resolution . resolvedTypeReferenceDirective === undefined ,
342344 /*reusedNames*/ undefined , /*logChanges*/ false
343345 ) ;
344346 }
@@ -348,6 +350,7 @@ namespace ts {
348350 moduleNames , containingFile , redirectedReference ,
349351 resolvedModuleNames , perDirectoryResolvedModuleNames ,
350352 resolveModuleName , getResolvedModule ,
353+ /*shouldRetryResolution*/ resolution => ! resolution . resolvedModule || ! resolutionExtensionIsTSOrJson ( resolution . resolvedModule . extension ) ,
351354 reusedNames , logChangesWhenResolvingModule
352355 ) ;
353356 }
0 commit comments