@@ -461,28 +461,32 @@ namespace ts.codefix {
461461 const defaultExport = checker . tryGetMemberInModuleExports ( InternalSymbolName . Default , moduleSymbol ) ;
462462 if ( defaultExport ) return { symbol : defaultExport , kind : ImportKind . Default } ;
463463 const exportEquals = checker . resolveExternalModuleSymbol ( moduleSymbol ) ;
464- return exportEquals === moduleSymbol ? undefined : { symbol : exportEquals , kind : getExportEqualsImportKind ( importingFile , compilerOptions , checker ) } ;
464+ return exportEquals === moduleSymbol ? undefined : { symbol : exportEquals , kind : getExportEqualsImportKind ( importingFile , compilerOptions ) } ;
465465 }
466466
467- function getExportEqualsImportKind ( importingFile : SourceFile , compilerOptions : CompilerOptions , checker : TypeChecker ) : ImportKind {
467+ function getExportEqualsImportKind ( importingFile : SourceFile , compilerOptions : CompilerOptions ) : ImportKind {
468+ const allowSyntheticDefaults = getAllowSyntheticDefaultImports ( compilerOptions ) ;
469+ // 1. 'import =' will not work in es2015+, so the decision is between a default
470+ // and a namespace import, based on allowSyntheticDefaultImports/esModuleInterop.
468471 if ( getEmitModuleKind ( compilerOptions ) >= ModuleKind . ES2015 ) {
469- return getAllowSyntheticDefaultImports ( compilerOptions ) ? ImportKind . Default : ImportKind . Namespace ;
472+ return allowSyntheticDefaults ? ImportKind . Default : ImportKind . Namespace ;
470473 }
474+ // 2. 'import =' will not work in JavaScript, so the decision is between a default
475+ // and const/require.
471476 if ( isInJSFile ( importingFile ) ) {
472477 return isExternalModule ( importingFile ) ? ImportKind . Default : ImportKind . ConstEquals ;
473478 }
479+ // 3. At this point the most correct choice is probably 'import =', but people
480+ // really hate that, so look to see if the importing file has any precedent
481+ // on how to handle it.
474482 for ( const statement of importingFile . statements ) {
475483 if ( isImportEqualsDeclaration ( statement ) ) {
476484 return ImportKind . Equals ;
477485 }
478- if ( isImportDeclaration ( statement ) && statement . importClause && statement . importClause . name ) {
479- const moduleSymbol = checker . getImmediateAliasedSymbol ( statement . importClause . symbol ) ;
480- if ( moduleSymbol && moduleSymbol . name !== InternalSymbolName . Default ) {
481- return ImportKind . Default ;
482- }
483- }
484486 }
485- return ImportKind . Equals ;
487+ // 4. We have no precedent to go on, so just use a default import if
488+ // allowSyntheticDefaultImports/esModuleInterop is enabled.
489+ return allowSyntheticDefaults ? ImportKind . Default : ImportKind . Equals ;
486490 }
487491
488492 function getDefaultExportInfoWorker ( defaultExport : Symbol , moduleSymbol : Symbol , checker : TypeChecker , compilerOptions : CompilerOptions ) : { readonly symbolForMeaning : Symbol , readonly name : string } | undefined {
0 commit comments