@@ -16,7 +16,7 @@ import {
16
16
ModuleSpecifierResolutionHost , NodeFlags , NodeModulePathParts , normalizePath , Path , pathContainsNodeModules ,
17
17
pathIsBareSpecifier , pathIsRelative , PropertyAccessExpression , removeFileExtension , removeSuffix , resolvePath ,
18
18
ScriptKind , some , SourceFile , startsWith , startsWithDirectory , stringContains , StringLiteral , Symbol , SymbolFlags ,
19
- toPath , tryGetExtensionFromPath , tryParsePatterns , TypeChecker , UserPreferences , shouldAllowImportingTsExtension , ResolutionMode , ModuleSpecifierEnding , getModuleSpecifierEndingPreference ,
19
+ toPath , tryGetExtensionFromPath , tryParsePatterns , TypeChecker , UserPreferences , shouldAllowImportingTsExtension , ResolutionMode , ModuleSpecifierEnding , getModuleSpecifierEndingPreference , isDeclarationFileName ,
20
20
} from "./_namespaces/ts" ;
21
21
22
22
// Used by importFixes, getEditsForFileRename, and declaration emit to synthesize import module specifiers.
@@ -74,10 +74,10 @@ function getPreferences(
74
74
if ( endsWith ( oldImportSpecifier , "/index" ) ) return ModuleSpecifierEnding . Index ;
75
75
}
76
76
return getModuleSpecifierEndingPreference (
77
- importModuleSpecifierEnding ,
78
- importingSourceFile . impliedNodeFormat ,
79
- compilerOptions ,
80
- importingSourceFile ) ;
77
+ importModuleSpecifierEnding ,
78
+ importingSourceFile . impliedNodeFormat ,
79
+ compilerOptions ,
80
+ importingSourceFile ) ;
81
81
}
82
82
}
83
83
@@ -937,10 +937,19 @@ function getPathsRelativeToRootDirs(path: string, rootDirs: readonly string[], g
937
937
}
938
938
939
939
function processEnding ( fileName : string , ending : ModuleSpecifierEnding , options : CompilerOptions , host ?: ModuleSpecifierResolutionHost ) : string {
940
- if ( fileExtensionIsOneOf ( fileName , [ Extension . Json , Extension . Mjs , Extension . Cjs ] ) ) return fileName ;
940
+ if ( fileExtensionIsOneOf ( fileName , [ Extension . Json , Extension . Mjs , Extension . Cjs ] ) ) {
941
+ return fileName ;
942
+ }
943
+
941
944
const noExtension = removeFileExtension ( fileName ) ;
942
- if ( fileName === noExtension ) return fileName ;
943
- if ( fileExtensionIsOneOf ( fileName , [ Extension . Dmts , Extension . Mts , Extension . Dcts , Extension . Cts ] ) ) return noExtension + getJSExtensionForFile ( fileName , options ) ;
945
+ if ( fileName === noExtension ) {
946
+ return fileName ;
947
+ }
948
+
949
+ if ( fileExtensionIsOneOf ( fileName , [ Extension . Dmts , Extension . Mts , Extension . Dcts , Extension . Cts ] ) ) {
950
+ return noExtension + getJSExtensionForFile ( fileName , options ) ;
951
+ }
952
+
944
953
switch ( ending ) {
945
954
case ModuleSpecifierEnding . Minimal :
946
955
const withoutIndex = removeSuffix ( noExtension , "/index" ) ;
@@ -955,7 +964,9 @@ function processEnding(fileName: string, ending: ModuleSpecifierEnding, options:
955
964
case ModuleSpecifierEnding . JsExtension :
956
965
return noExtension + getJSExtensionForFile ( fileName , options ) ;
957
966
case ModuleSpecifierEnding . TsExtension :
958
- return fileName ;
967
+ // For now, we don't know if this import is going to be type-only, which means we don't
968
+ // know if a .d.ts extension is valid, so use the .js extension.
969
+ return isDeclarationFileName ( fileName ) ? noExtension + getJSExtensionForFile ( fileName , options ) : fileName ;
959
970
default :
960
971
return Debug . assertNever ( ending ) ;
961
972
}
0 commit comments