File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -403,10 +403,12 @@ namespace ts {
403403
404404 const resolvedFileName = result . resolvedModule && result . resolvedModule . resolvedFileName ;
405405 // find common prefix between directory and resolved file name
406- // this common prefix should be the shorted path that has the same resolution
406+ // this common prefix should be the shortest path that has the same resolution
407407 // directory: /a/b/c/d/e
408408 // resolvedFileName: /a/b/foo.d.ts
409- const commonPrefix = getCommonPrefix ( path , resolvedFileName ) ;
409+ // commonPrefix: /a/b
410+ // for failed lookups use the root directory as commonPrefix
411+ const commonPrefix = resolvedFileName ? getCommonPrefix ( path , resolvedFileName ) : path . substr ( 0 , getRootLength ( path ) ) ;
410412 if ( ! commonPrefix ) {
411413 return ;
412414 }
@@ -421,10 +423,7 @@ namespace ts {
421423 }
422424 }
423425
424- function getCommonPrefix ( directory : Path , resolution : string | undefined ) {
425- if ( resolution === undefined ) {
426- return undefined ;
427- }
426+ function getCommonPrefix ( directory : Path , resolution : string ) {
428427 const resolutionDirectory = toPath ( getDirectoryPath ( resolution ) , currentDirectory , getCanonicalFileName ) ;
429428
430429 let current = directory ;
Original file line number Diff line number Diff line change @@ -264,6 +264,16 @@ namespace ts {
264264 assert . isDefined ( cache . get ( "c:/foo" ) ) ;
265265 assert . isUndefined ( cache . get ( "c:/" ) ) ;
266266 assert . isUndefined ( cache . get ( "d:/" ) ) ;
267+
268+ cache = resolutionCache . getOrCreateCacheForModuleName ( "f" ) ;
269+ cache . set ( "/foo/bar/baz" , {
270+ resolvedModule : undefined ,
271+ failedLookupLocations : [ ] ,
272+ } ) ;
273+ assert . isDefined ( cache . get ( "/foo/bar/baz" ) ) ;
274+ assert . isDefined ( cache . get ( "/foo/bar" ) ) ;
275+ assert . isDefined ( cache . get ( "/foo" ) ) ;
276+ assert . isDefined ( cache . get ( "/" ) ) ;
267277 } ) ;
268278
269279 it ( "load module as file - ts files not loaded" , ( ) => {
You can’t perform that action at this time.
0 commit comments