@@ -87,11 +87,9 @@ namespace ts.moduleSpecifiers {
87
87
function getLocalModuleSpecifiers (
88
88
moduleFileName : string ,
89
89
{ moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory } : Info ,
90
- compilerOptions : CompilerOptions ,
90
+ { baseUrl , paths , rootDirs } : CompilerOptions ,
91
91
preferences : ModuleSpecifierPreferences ,
92
92
) : ReadonlyArray < string > {
93
- const { baseUrl, paths, rootDirs } = compilerOptions ;
94
-
95
93
const relativePath = rootDirs && tryGetModuleNameFromRootDirs ( rootDirs , moduleFileName , sourceDirectory , getCanonicalFileName ) ||
96
94
removeExtensionAndIndexPostFix ( ensurePathIsNonModuleName ( getRelativePathFromDirectory ( sourceDirectory , moduleFileName , getCanonicalFileName ) ) , moduleResolutionKind , addJsExtension ) ;
97
95
if ( ! baseUrl || preferences . importModuleSpecifierPreference === "relative" ) {
@@ -105,23 +103,21 @@ namespace ts.moduleSpecifiers {
105
103
106
104
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix ( relativeToBaseUrl , moduleResolutionKind , addJsExtension ) ;
107
105
const fromPaths = paths && tryGetModuleNameFromPaths ( removeFileExtension ( relativeToBaseUrl ) , importRelativeToBaseUrl , paths ) ;
108
- if ( fromPaths ) {
109
- return [ fromPaths ] ;
110
- }
106
+ const nonRelative = fromPaths === undefined ? importRelativeToBaseUrl : fromPaths ;
111
107
112
108
if ( preferences . importModuleSpecifierPreference === "non-relative" ) {
113
- return [ importRelativeToBaseUrl ] ;
109
+ return [ nonRelative ] ;
114
110
}
115
111
116
112
if ( preferences . importModuleSpecifierPreference !== undefined ) Debug . assertNever ( preferences . importModuleSpecifierPreference ) ;
117
113
118
- if ( isPathRelativeToParent ( relativeToBaseUrl ) ) {
114
+ if ( isPathRelativeToParent ( nonRelative ) ) {
119
115
return [ relativePath ] ;
120
116
}
121
117
122
118
// Prefer a relative import over a baseUrl import if it has fewer components.
123
- const relativeFirst = countPathComponents ( relativePath ) < countPathComponents ( importRelativeToBaseUrl ) ;
124
- return relativeFirst ? [ relativePath , importRelativeToBaseUrl ] : [ importRelativeToBaseUrl , relativePath ] ;
119
+ const relativeFirst = countPathComponents ( relativePath ) < countPathComponents ( nonRelative ) ;
120
+ return relativeFirst ? [ relativePath , nonRelative ] : [ nonRelative , relativePath ] ;
125
121
}
126
122
127
123
function countPathComponents ( path : string ) : number {
0 commit comments