@@ -491,12 +491,7 @@ namespace ts.codefix {
491491
492492 function getFixesInfoForNonUMDImport ( { sourceFile, program, cancellationToken, host, preferences } : CodeFixContextBase , symbolToken : Identifier , useAutoImportProvider : boolean ) : FixesInfo | undefined {
493493 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 ) ;
500495 // "default" is a keyword and not a legal identifier for the import, so we don't expect it here
501496 Debug . assert ( symbolName !== InternalSymbolName . Default , "'default' isn't a legal identifier and couldn't occur here" ) ;
502497
@@ -509,6 +504,17 @@ namespace ts.codefix {
509504 return { fixes, symbolName } ;
510505 }
511506
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+
512518 // Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
513519 function getExportInfos (
514520 symbolName : string ,
0 commit comments