33namespace ts . moduleSpecifiers {
44 export interface ModuleSpecifierPreferences {
55 importModuleSpecifierPreference ?: "relative" | "non-relative" ;
6+ includingJsExtensionOnAutoImports ?: boolean ;
67 }
78
89 // Note: fromSourceFile is just for usesJsExtensionOnImports
910 export function getModuleSpecifier ( compilerOptions : CompilerOptions , fromSourceFile : SourceFile , fromSourceFileName : string , toFileName : string , host : ModuleSpecifierResolutionHost , preferences : ModuleSpecifierPreferences = { } ) {
10- const info = getInfo ( compilerOptions , fromSourceFile , fromSourceFileName , host ) ;
11+ const info = getInfo ( compilerOptions , fromSourceFile , fromSourceFileName , host , preferences ) ;
1112 return getGlobalModuleSpecifier ( toFileName , info , host , compilerOptions ) ||
1213 first ( getLocalModuleSpecifiers ( toFileName , info , compilerOptions , preferences ) ) ;
1314 }
@@ -24,7 +25,7 @@ namespace ts.moduleSpecifiers {
2425 const ambient = tryGetModuleNameFromAmbientModule ( moduleSymbol ) ;
2526 if ( ambient ) return [ [ ambient ] ] ;
2627
27- const info = getInfo ( compilerOptions , importingSourceFile , importingSourceFile . path , host ) ;
28+ const info = getInfo ( compilerOptions , importingSourceFile , importingSourceFile . path , host , preferences ) ;
2829 if ( ! files ) {
2930 return Debug . fail ( "Files list must be present to resolve symlinks in specifier resolution" ) ;
3031 }
@@ -42,9 +43,9 @@ namespace ts.moduleSpecifiers {
4243 readonly sourceDirectory : string ;
4344 }
4445 // importingSourceFileName is separate because getEditsForFileRename may need to specify an updated path
45- function getInfo ( compilerOptions : CompilerOptions , importingSourceFile : SourceFile , importingSourceFileName : string , host : ModuleSpecifierResolutionHost ) : Info {
46+ function getInfo ( compilerOptions : CompilerOptions , importingSourceFile : SourceFile , importingSourceFileName : string , host : ModuleSpecifierResolutionHost , preferences : ModuleSpecifierPreferences ) : Info {
4647 const moduleResolutionKind = getEmitModuleResolutionKind ( compilerOptions ) ;
47- const addJsExtension = usesJsExtensionOnImports ( importingSourceFile ) ;
48+ const addJsExtension = usesJsExtensionOnImports ( importingSourceFile , preferences ) ;
4849 const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ? host . useCaseSensitiveFileNames ( ) : true ) ;
4950 const sourceDirectory = getDirectoryPath ( importingSourceFileName ) ;
5051 return { moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory } ;
@@ -129,8 +130,8 @@ namespace ts.moduleSpecifiers {
129130 return relativeFirst ? [ relativePath , importRelativeToBaseUrl ] : [ importRelativeToBaseUrl , relativePath ] ;
130131 }
131132
132- function usesJsExtensionOnImports ( { imports } : SourceFile ) : boolean {
133- return firstDefined ( imports , ( { text } ) => pathIsRelative ( text ) ? fileExtensionIs ( text , Extension . Js ) : undefined ) || false ;
133+ function usesJsExtensionOnImports ( { imports } : SourceFile , preferences : ModuleSpecifierPreferences ) : boolean {
134+ return firstDefined ( imports , ( { text } ) => pathIsRelative ( text ) ? fileExtensionIs ( text , Extension . Js ) : undefined ) || ! ! preferences . includingJsExtensionOnAutoImports ;
134135 }
135136
136137 function discoverProbableSymlinks ( files : ReadonlyArray < SourceFile > , getCanonicalFileName : ( file : string ) => string , host : ModuleSpecifierResolutionHost ) {
0 commit comments