@@ -36,7 +36,7 @@ namespace ts {
36
36
}
37
37
38
38
export function resolveModuleName ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost ) : ResolvedModule {
39
- switch ( compilerOptions . moduleResolution ) {
39
+ switch ( compilerOptions . moduleResolution ) {
40
40
case ModuleResolutionKind . NodeJs : return nodeModuleNameResolver ( moduleName , containingFile , host ) ;
41
41
case ModuleResolutionKind . BaseUrl : return baseUrlModuleNameResolver ( moduleName , containingFile , compilerOptions . baseUrl , host ) ;
42
42
default : return legacyNameResolver ( moduleName , containingFile , compilerOptions , host ) ;
@@ -141,26 +141,7 @@ namespace ts {
141
141
142
142
let failedLookupLocations : string [ ] = [ ] ;
143
143
144
- let hasSupportedExtension = forEach ( supportedExtensions , ext => fileExtensionIs ( candidate , ext ) ) ;
145
-
146
- if ( hasSupportedExtension ) {
147
- // module name already has extension - use it as is
148
- let result = tryLoadFile ( candidate ) ;
149
- if ( result ) {
150
- return result ;
151
- }
152
- }
153
- else {
154
- // module name does not have extension - try every supported extension
155
- for ( let ext of supportedExtensions ) {
156
- let result = tryLoadFile ( candidate + ext ) ;
157
- if ( result ) {
158
- return result ;
159
- }
160
- }
161
- }
162
-
163
- return { resolvedFileName : undefined , failedLookupLocations } ;
144
+ return forEach ( supportedExtensions , ext => tryLoadFile ( candidate + ext ) ) || { resolvedFileName : undefined , failedLookupLocations } ;
164
145
165
146
function tryLoadFile ( location : string ) : ResolvedModule {
166
147
if ( host . fileExists ( location ) ) {
@@ -179,23 +160,9 @@ namespace ts {
179
160
}
180
161
181
162
function useBaseUrl ( moduleName : string ) : boolean {
182
- // path is rooted
183
- if ( getRootLength ( moduleName ) !== 0 ) {
184
- return false ;
185
- }
186
-
187
- // module name starts with './' or '../'
188
- if ( nameStartsWithDotSlashOrDotDotSlash ( moduleName ) ) {
189
- return false ;
190
- }
191
-
192
- // module name has one of supported extesions
193
- for ( let ext of supportedExtensions ) {
194
- if ( fileExtensionIs ( moduleName , ext ) ) {
195
- return false ;
196
- }
197
- }
198
- return true ;
163
+ // path is not rooted
164
+ // module name does not start with './' or '../'
165
+ return getRootLength ( moduleName ) === 0 && ! nameStartsWithDotSlashOrDotDotSlash ( moduleName ) ;
199
166
}
200
167
201
168
export function legacyNameResolver ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost ) : ResolvedModule {
0 commit comments