@@ -491,12 +491,7 @@ namespace ts.codefix {
491
491
492
492
function getFixesInfoForNonUMDImport ( { sourceFile, program, cancellationToken, host, preferences } : CodeFixContextBase , symbolToken : Identifier , useAutoImportProvider : boolean ) : FixesInfo | undefined {
493
493
const checker = program . getTypeChecker ( ) ;
494
- // If we're at `<Foo/>`, we must check if `Foo` is already in scope, and if so, get an import for `React` instead.
495
- const symbolName = isJsxOpeningLikeElement ( symbolToken . parent )
496
- && symbolToken . parent . tagName === symbolToken
497
- && ( isIntrinsicJsxName ( symbolToken . text ) || checker . resolveName ( symbolToken . text , symbolToken , SymbolFlags . All , /*excludeGlobals*/ false ) )
498
- ? checker . getJsxNamespace ( sourceFile )
499
- : symbolToken . text ;
494
+ const symbolName = getSymbolName ( sourceFile , checker , symbolToken ) ;
500
495
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
501
496
Debug . assert ( symbolName !== InternalSymbolName . Default , "'default' isn't a legal identifier and couldn't occur here" ) ;
502
497
@@ -509,6 +504,17 @@ namespace ts.codefix {
509
504
return { fixes, symbolName } ;
510
505
}
511
506
507
+ function getSymbolName ( sourceFile : SourceFile , checker : TypeChecker , symbolToken : Identifier ) : string {
508
+ const parent = symbolToken . parent ;
509
+ if ( ( isJsxOpeningLikeElement ( parent ) || isJsxClosingElement ( parent ) ) && parent . tagName === symbolToken ) {
510
+ const jsxNamespace = checker . getJsxNamespace ( sourceFile ) ;
511
+ if ( isIntrinsicJsxName ( symbolToken . text ) || ! checker . resolveName ( jsxNamespace , parent , SymbolFlags . Value , /*excludeGlobals*/ true ) ) {
512
+ return jsxNamespace ;
513
+ }
514
+ }
515
+ return symbolToken . text ;
516
+ }
517
+
512
518
// Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
513
519
function getExportInfos (
514
520
symbolName : string ,
0 commit comments