@@ -485,12 +485,7 @@ namespace ts.codefix {
485485
486486 function getFixesInfoForNonUMDImport ( { sourceFile, program, cancellationToken, host, preferences } : CodeFixContextBase , symbolToken : Identifier ) : FixesInfo | undefined {
487487 const checker = program . getTypeChecker ( ) ;
488- // If we're at `<Foo/>`, we must check if `Foo` is already in scope, and if so, get an import for `React` instead.
489- const symbolName = isJsxOpeningLikeElement ( symbolToken . parent )
490- && symbolToken . parent . tagName === symbolToken
491- && ( isIntrinsicJsxName ( symbolToken . text ) || checker . resolveName ( symbolToken . text , symbolToken , SymbolFlags . All , /*excludeGlobals*/ false ) )
492- ? checker . getJsxNamespace ( sourceFile )
493- : symbolToken . text ;
488+ const symbolName = getSymbolName ( sourceFile , checker , symbolToken ) ;
494489 // "default" is a keyword and not a legal identifier for the import, so we don't expect it here
495490 Debug . assert ( symbolName !== InternalSymbolName . Default , "'default' isn't a legal identifier and couldn't occur here" ) ;
496491
@@ -503,6 +498,17 @@ namespace ts.codefix {
503498 return { fixes, symbolName } ;
504499 }
505500
501+ function getSymbolName ( sourceFile : SourceFile , checker : TypeChecker , symbolToken : Identifier ) : string {
502+ const parent = symbolToken . parent ;
503+ if ( ( isJsxOpeningLikeElement ( parent ) || isJsxClosingElement ( parent ) ) && parent . tagName === symbolToken ) {
504+ const jsxNamespace = checker . getJsxNamespace ( sourceFile ) ;
505+ if ( isIntrinsicJsxName ( symbolToken . text ) || ! checker . resolveName ( jsxNamespace , parent , SymbolFlags . All , /*excludeGlobals*/ true ) ) {
506+ return jsxNamespace ;
507+ }
508+ }
509+ return symbolToken . text ;
510+ }
511+
506512 // Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
507513 function getExportInfos (
508514 symbolName : string ,
0 commit comments