@@ -74,7 +74,7 @@ namespace ts.codefix {
74
74
const symbolName = getNameForExportedSymbol ( exportedSymbol , getEmitScriptTarget ( compilerOptions ) ) ;
75
75
const checker = program . getTypeChecker ( ) ;
76
76
const symbol = checker . getMergedSymbol ( skipAlias ( exportedSymbol , checker ) ) ;
77
- const exportInfos = getAllReExportingModules ( sourceFile , symbol , moduleSymbol , symbolName , host , program , preferences , useAutoImportProvider ) ;
77
+ const exportInfos = getAllReExportingModules ( sourceFile , symbol , moduleSymbol , symbolName , /*isJsxTagName*/ false , host , program , preferences , useAutoImportProvider ) ;
78
78
const useRequire = shouldUseRequire ( sourceFile , program ) ;
79
79
const fix = getImportFixForSymbol ( sourceFile , exportInfos , moduleSymbol , symbolName , program , /*position*/ undefined , ! ! isValidTypeOnlyUseSite , useRequire , host , preferences ) ;
80
80
if ( fix ) {
@@ -287,6 +287,7 @@ namespace ts.codefix {
287
287
moduleSymbol : Symbol ,
288
288
sourceFile : SourceFile ,
289
289
symbolName : string ,
290
+ isJsxTagName : boolean ,
290
291
host : LanguageServiceHost ,
291
292
program : Program ,
292
293
formatContext : formatting . FormatContext ,
@@ -296,7 +297,7 @@ namespace ts.codefix {
296
297
const compilerOptions = program . getCompilerOptions ( ) ;
297
298
const exportInfos = pathIsBareSpecifier ( stripQuotes ( moduleSymbol . name ) )
298
299
? [ getSymbolExportInfoForSymbol ( targetSymbol , moduleSymbol , program , host ) ]
299
- : getAllReExportingModules ( sourceFile , targetSymbol , moduleSymbol , symbolName , host , program , preferences , /*useAutoImportProvider*/ true ) ;
300
+ : getAllReExportingModules ( sourceFile , targetSymbol , moduleSymbol , symbolName , isJsxTagName , host , program , preferences , /*useAutoImportProvider*/ true ) ;
300
301
const useRequire = shouldUseRequire ( sourceFile , program ) ;
301
302
const isValidTypeOnlyUseSite = isValidTypeOnlyAliasUseSite ( getTokenAtPosition ( sourceFile , position ) ) ;
302
303
const fix = Debug . checkDefined ( getImportFixForSymbol ( sourceFile , exportInfos , moduleSymbol , symbolName , program , position , isValidTypeOnlyUseSite , useRequire , host , preferences ) ) ;
@@ -349,7 +350,7 @@ namespace ts.codefix {
349
350
}
350
351
}
351
352
352
- function getAllReExportingModules ( importingFile : SourceFile , targetSymbol : Symbol , exportingModuleSymbol : Symbol , symbolName : string , host : LanguageServiceHost , program : Program , preferences : UserPreferences , useAutoImportProvider : boolean ) : readonly SymbolExportInfo [ ] {
353
+ function getAllReExportingModules ( importingFile : SourceFile , targetSymbol : Symbol , exportingModuleSymbol : Symbol , symbolName : string , isJsxTagName : boolean , host : LanguageServiceHost , program : Program , preferences : UserPreferences , useAutoImportProvider : boolean ) : readonly SymbolExportInfo [ ] {
353
354
const result : SymbolExportInfo [ ] = [ ] ;
354
355
const compilerOptions = program . getCompilerOptions ( ) ;
355
356
const getModuleSpecifierResolutionHost = memoizeOne ( ( isFromPackageJson : boolean ) => {
@@ -364,7 +365,7 @@ namespace ts.codefix {
364
365
}
365
366
366
367
const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker , compilerOptions ) ;
367
- if ( defaultInfo && ( defaultInfo . name === symbolName || moduleSymbolToValidIdentifier ( moduleSymbol , getEmitScriptTarget ( compilerOptions ) ) === symbolName ) && skipAlias ( defaultInfo . symbol , checker ) === targetSymbol && isImportable ( program , moduleFile , isFromPackageJson ) ) {
368
+ if ( defaultInfo && ( defaultInfo . name === symbolName || moduleSymbolToValidIdentifier ( moduleSymbol , getEmitScriptTarget ( compilerOptions ) , isJsxTagName ) === symbolName ) && skipAlias ( defaultInfo . symbol , checker ) === targetSymbol && isImportable ( program , moduleFile , isFromPackageJson ) ) {
368
369
result . push ( { symbol : defaultInfo . symbol , moduleSymbol, moduleFileName : moduleFile ?. fileName , exportKind : defaultInfo . exportKind , targetFlags : skipAlias ( defaultInfo . symbol , checker ) . flags , isFromPackageJson } ) ;
369
370
}
370
371
@@ -804,7 +805,7 @@ namespace ts.codefix {
804
805
805
806
const isValidTypeOnlyUseSite = isValidTypeOnlyAliasUseSite ( symbolToken ) ;
806
807
const useRequire = shouldUseRequire ( sourceFile , program ) ;
807
- const exportInfos = getExportInfos ( symbolName , getMeaningFromLocation ( symbolToken ) , cancellationToken , sourceFile , program , useAutoImportProvider , host , preferences ) ;
808
+ const exportInfos = getExportInfos ( symbolName , isJSXTagName ( symbolToken ) , getMeaningFromLocation ( symbolToken ) , cancellationToken , sourceFile , program , useAutoImportProvider , host , preferences ) ;
808
809
const fixes = arrayFrom ( flatMapIterator ( exportInfos . entries ( ) , ( [ _ , exportInfos ] ) =>
809
810
getImportFixes ( exportInfos , symbolName , symbolToken . getStart ( sourceFile ) , isValidTypeOnlyUseSite , useRequire , program , sourceFile , host , preferences ) ) ) ;
810
811
return { fixes, symbolName } ;
@@ -845,6 +846,7 @@ namespace ts.codefix {
845
846
// Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
846
847
function getExportInfos (
847
848
symbolName : string ,
849
+ isJsxTagName : boolean ,
848
850
currentTokenMeaning : SemanticMeaning ,
849
851
cancellationToken : CancellationToken ,
850
852
fromFile : SourceFile ,
@@ -876,7 +878,7 @@ namespace ts.codefix {
876
878
877
879
const compilerOptions = program . getCompilerOptions ( ) ;
878
880
const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker , compilerOptions ) ;
879
- if ( defaultInfo && ( defaultInfo . name === symbolName || moduleSymbolToValidIdentifier ( moduleSymbol , getEmitScriptTarget ( compilerOptions ) ) === symbolName ) && symbolHasMeaning ( defaultInfo . symbolForMeaning , currentTokenMeaning ) ) {
881
+ if ( defaultInfo && ( defaultInfo . name === symbolName || moduleSymbolToValidIdentifier ( moduleSymbol , getEmitScriptTarget ( compilerOptions ) , isJsxTagName ) === symbolName ) && symbolHasMeaning ( defaultInfo . symbolForMeaning , currentTokenMeaning ) ) {
880
882
addSymbol ( moduleSymbol , sourceFile , defaultInfo . symbol , defaultInfo . exportKind , program , isFromPackageJson ) ;
881
883
}
882
884
@@ -1237,17 +1239,20 @@ namespace ts.codefix {
1237
1239
return some ( declarations , decl => ! ! ( getMeaningFromDeclaration ( decl ) & meaning ) ) ;
1238
1240
}
1239
1241
1240
- export function moduleSymbolToValidIdentifier ( moduleSymbol : Symbol , target : ScriptTarget | undefined ) : string {
1241
- return moduleSpecifierToValidIdentifier ( removeFileExtension ( stripQuotes ( moduleSymbol . name ) ) , target ) ;
1242
+ export function moduleSymbolToValidIdentifier ( moduleSymbol : Symbol , target : ScriptTarget | undefined , forceCapitalize : boolean ) : string {
1243
+ return moduleSpecifierToValidIdentifier ( removeFileExtension ( stripQuotes ( moduleSymbol . name ) ) , target , forceCapitalize ) ;
1242
1244
}
1243
1245
1244
- export function moduleSpecifierToValidIdentifier ( moduleSpecifier : string , target : ScriptTarget | undefined ) : string {
1246
+ export function moduleSpecifierToValidIdentifier ( moduleSpecifier : string , target : ScriptTarget | undefined , forceCapitalize ?: boolean ) : string {
1245
1247
const baseName = getBaseFileName ( removeSuffix ( moduleSpecifier , "/index" ) ) ;
1246
1248
let res = "" ;
1247
1249
let lastCharWasValid = true ;
1248
1250
const firstCharCode = baseName . charCodeAt ( 0 ) ;
1249
1251
if ( isIdentifierStart ( firstCharCode , target ) ) {
1250
1252
res += String . fromCharCode ( firstCharCode ) ;
1253
+ if ( forceCapitalize ) {
1254
+ res = res . toUpperCase ( ) ;
1255
+ }
1251
1256
}
1252
1257
else {
1253
1258
lastCharWasValid = false ;
0 commit comments