@@ -26,6 +26,7 @@ import {
26
26
emptyArray ,
27
27
EnumDeclaration ,
28
28
escapeLeadingUnderscores ,
29
+ every ,
29
30
ExportDeclaration ,
30
31
ExportKind ,
31
32
Expression ,
@@ -885,24 +886,23 @@ export function getUsageInfo(oldFile: SourceFile, toMove: readonly Statement[],
885
886
const unusedImportsFromOldFile = new Set < Symbol > ( ) ;
886
887
for ( const statement of toMove ) {
887
888
forEachReference ( statement , checker , enclosingRange , ( symbol , isValidTypeOnlyUseSite ) => {
888
- if ( ! symbol . declarations || isGlobalType ( checker , symbol ) ) {
889
+ if ( ! symbol . declarations ) {
889
890
return ;
890
891
}
891
892
if ( existingTargetLocals . has ( skipAlias ( symbol , checker ) ) ) {
892
893
unusedImportsFromOldFile . add ( symbol ) ;
893
894
return ;
894
895
}
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 ) ;
906
906
}
907
907
} ) ;
908
908
}
@@ -946,10 +946,6 @@ export function getUsageInfo(oldFile: SourceFile, toMove: readonly Statement[],
946
946
}
947
947
}
948
948
949
- function isGlobalType ( checker : TypeChecker , symbol : Symbol ) {
950
- return ! ! checker . resolveName ( symbol . name , /*location*/ undefined , SymbolFlags . Type , /*excludeGlobals*/ false ) ;
951
- }
952
-
953
949
function makeUniqueFilename ( proposedFilename : string , extension : string , inDirectory : string , host : LanguageServiceHost ) : string {
954
950
let newFilename = proposedFilename ;
955
951
for ( let i = 1 ; ; i ++ ) {
0 commit comments