@@ -26,6 +26,7 @@ import {
2626 emptyArray ,
2727 EnumDeclaration ,
2828 escapeLeadingUnderscores ,
29+ every ,
2930 ExportDeclaration ,
3031 ExportKind ,
3132 Expression ,
@@ -885,24 +886,23 @@ export function getUsageInfo(oldFile: SourceFile, toMove: readonly Statement[],
885886 const unusedImportsFromOldFile = new Set < Symbol > ( ) ;
886887 for ( const statement of toMove ) {
887888 forEachReference ( statement , checker , enclosingRange , ( symbol , isValidTypeOnlyUseSite ) => {
888- if ( ! symbol . declarations || isGlobalType ( checker , symbol ) ) {
889+ if ( ! symbol . declarations ) {
889890 return ;
890891 }
891892 if ( existingTargetLocals . has ( skipAlias ( symbol , checker ) ) ) {
892893 unusedImportsFromOldFile . add ( symbol ) ;
893894 return ;
894895 }
895- for ( const decl of symbol . declarations ) {
896- if ( isInImport ( decl ) ) {
897- const prevIsTypeOnly = oldImportsNeededByTargetFile . get ( symbol ) ;
898- oldImportsNeededByTargetFile . set ( symbol , [
899- prevIsTypeOnly === undefined ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite ,
900- tryCast ( decl , ( d ) : d is codefix . ImportOrRequireAliasDeclaration => isImportSpecifier ( d ) || isImportClause ( d ) || isNamespaceImport ( d ) || isImportEqualsDeclaration ( d ) || isBindingElement ( d ) || isVariableDeclaration ( d ) ) ,
901- ] ) ;
902- }
903- else if ( isTopLevelDeclaration ( decl ) && sourceFileOfTopLevelDeclaration ( decl ) === oldFile && ! movedSymbols . has ( symbol ) ) {
904- targetFileImportsFromOldFile . set ( symbol , isValidTypeOnlyUseSite ) ;
905- }
896+ const importedDeclaration = find ( symbol . declarations , isInImport ) ;
897+ if ( importedDeclaration ) {
898+ const prevIsTypeOnly = oldImportsNeededByTargetFile . get ( symbol ) ;
899+ oldImportsNeededByTargetFile . set ( symbol , [
900+ prevIsTypeOnly === undefined ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite ,
901+ tryCast ( importedDeclaration , ( d ) : d is codefix . ImportOrRequireAliasDeclaration => isImportSpecifier ( d ) || isImportClause ( d ) || isNamespaceImport ( d ) || isImportEqualsDeclaration ( d ) || isBindingElement ( d ) || isVariableDeclaration ( d ) ) ,
902+ ] ) ;
903+ }
904+ else if ( ! movedSymbols . has ( symbol ) && every ( symbol . declarations , decl => isTopLevelDeclaration ( decl ) && sourceFileOfTopLevelDeclaration ( decl ) === oldFile ) ) {
905+ targetFileImportsFromOldFile . set ( symbol , isValidTypeOnlyUseSite ) ;
906906 }
907907 } ) ;
908908 }
@@ -946,10 +946,6 @@ export function getUsageInfo(oldFile: SourceFile, toMove: readonly Statement[],
946946 }
947947}
948948
949- function isGlobalType ( checker : TypeChecker , symbol : Symbol ) {
950- return ! ! checker . resolveName ( symbol . name , /*location*/ undefined , SymbolFlags . Type , /*excludeGlobals*/ false ) ;
951- }
952-
953949function makeUniqueFilename ( proposedFilename : string , extension : string , inDirectory : string , host : LanguageServiceHost ) : string {
954950 let newFilename = proposedFilename ;
955951 for ( let i = 1 ; ; i ++ ) {
0 commit comments