@@ -179,6 +179,10 @@ namespace ts {
179179 // NOTE: traceEnabled check is delibirately no inside the 'trace' at evert callside to avoid runtime impact of calling vararg function
180180 const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
181181
182+ if ( traceEnabled ) {
183+ trace ( host , Diagnostics . Base_url_Colon_0 , baseUrl ) ;
184+ }
185+
182186 if ( isRootedDiskPath ( moduleName ) ) {
183187 if ( traceEnabled ) {
184188 trace ( host , Diagnostics . Resolving_rooted_module_name_0_use_it_as_a_candidate_location , moduleName ) ;
@@ -211,6 +215,7 @@ namespace ts {
211215 function baseUrlResolveRelativeModuleName ( moduleName : string , containingFile : string , baseUrl : string , supportedExtensions : string [ ] , compilerOptions : CompilerOptions , host : ModuleResolutionHost , traceEnabled : boolean ) : ResolvedModuleWithFailedLookupLocations {
212216 const failedLookupLocations : string [ ] = [ ] ;
213217
218+ // we always pass absolute path to containing file so candidate location is also absolute
214219 const containingDirectory = getDirectoryPath ( containingFile ) ;
215220 const candidate = normalizePath ( combinePaths ( containingDirectory , moduleName ) ) ;
216221
@@ -225,14 +230,24 @@ namespace ts {
225230
226231 let matchedPrefix : string ;
227232 for ( const rootDir of compilerOptions . rootDirs ) {
228- let normalizedRoot = getNormalizedAbsolutePath ( rootDir , baseUrl ) ;
233+ // rootDirs are expected to be absolute
234+ let normalizedRoot = normalizePath ( rootDir ) ;
229235 if ( ! endsWith ( normalizedRoot , directorySeparator ) ) {
230236 normalizedRoot += directorySeparator ;
231237 }
232- if ( startsWith ( candidate , normalizedRoot ) && ( matchedPrefix === undefined || matchedPrefix . length < normalizedRoot . length ) ) {
238+ const isLongestMatchingPrefix =
239+ startsWith ( candidate , normalizedRoot ) &&
240+ ( matchedPrefix === undefined || matchedPrefix . length < normalizedRoot . length ) ;
241+
242+ if ( traceEnabled ) {
243+ trace ( host , Diagnostics . Checking_if_0_is_the_longest_matching_prefix_for_1_2 , normalizedRoot , candidate , isLongestMatchingPrefix ) ;
244+ }
245+
246+ if ( isLongestMatchingPrefix ) {
233247 matchedPrefix = normalizedRoot ;
234248 }
235249 }
250+
236251 if ( matchedPrefix ) {
237252 const suffix = candidate . substr ( matchedPrefix . length ) ;
238253 if ( traceEnabled ) {
@@ -241,19 +256,20 @@ namespace ts {
241256
242257 return baseUrlResolveNonRelativeModuleName ( suffix , baseUrl , supportedExtensions , compilerOptions , host , traceEnabled ) ;
243258 }
244- return { resolvedModule : undefined , failedLookupLocations } ;
259+
260+ // rootDirs does not contain prefix for candidate - fallthrough to load file from candidate location.
245261 }
246262 else {
247263 if ( traceEnabled ) {
248264 trace ( host , Diagnostics . rootDirs_option_is_not_specified_using_0_as_candidate_location , candidate ) ;
249265 }
250-
251- const resolvedFileName = loadModuleFromFile ( supportedExtensions , candidate , failedLookupLocations , host , traceEnabled ) ;
252- return {
253- resolvedModule : resolvedFileName ? { resolvedFileName } : undefined ,
254- failedLookupLocations
255- } ;
256266 }
267+
268+ const resolvedFileName = loadModuleFromFile ( supportedExtensions , candidate , failedLookupLocations , host , traceEnabled ) ;
269+ return {
270+ resolvedModule : resolvedFileName ? { resolvedFileName } : undefined ,
271+ failedLookupLocations
272+ } ;
257273 }
258274
259275 function baseUrlResolveNonRelativeModuleName ( moduleName : string , baseUrl : string , supportedExtensions : string [ ] , compilerOptions : CompilerOptions , host : ModuleResolutionHost , traceEnabled : boolean ) : ResolvedModuleWithFailedLookupLocations {
0 commit comments