File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ namespace ts.refactor {
404
404
if ( isInImport ( decl ) ) {
405
405
oldImportsNeededByNewFile . add ( symbol ) ;
406
406
}
407
- else if ( isTopLevelDeclaration ( decl ) && ! movedSymbols . has ( symbol ) ) {
407
+ else if ( isTopLevelDeclaration ( decl ) && sourceFileOfTopLevelDeclaration ( decl ) === oldFile && ! movedSymbols . has ( symbol ) ) {
408
408
newFileImportsFromOldFile . add ( symbol ) ;
409
409
}
410
410
}
@@ -546,7 +546,11 @@ namespace ts.refactor {
546
546
interface TopLevelVariableDeclaration extends VariableDeclaration { parent : VariableDeclarationList & { parent : VariableStatement ; } ; }
547
547
type TopLevelDeclaration = NonVariableTopLevelDeclaration | TopLevelVariableDeclaration ;
548
548
function isTopLevelDeclaration ( node : Node ) : node is TopLevelDeclaration {
549
- return isNonVariableTopLevelDeclaration ( node ) || isVariableDeclaration ( node ) && isSourceFile ( node . parent . parent . parent ) ;
549
+ return isNonVariableTopLevelDeclaration ( node ) && isSourceFile ( node . parent ) || isVariableDeclaration ( node ) && isSourceFile ( node . parent . parent . parent ) ;
550
+ }
551
+
552
+ function sourceFileOfTopLevelDeclaration ( node : TopLevelDeclaration ) : Node {
553
+ return isVariableDeclaration ( node ) ? node . parent . parent . parent : node . parent ;
550
554
}
551
555
552
556
function isTopLevelDeclarationStatement ( node : Node ) : node is TopLevelDeclarationStatement {
Original file line number Diff line number Diff line change 4
4
////import './foo';
5
5
////import { a, b, alreadyUnused } from './other';
6
6
////const p = 0;
7
- ////[|const y = p + b;|]
7
+ ////[|const y: Date = p + b;|]
8
8
////a; y;
9
9
10
10
verify . moveToNewFile ( {
@@ -20,7 +20,7 @@ a; y;`,
20
20
"/y.ts" :
21
21
`import { b } from './other';
22
22
import { p } from './a';
23
- export const y = p + b;` ,
23
+ export const y: Date = p + b;` ,
24
24
} ,
25
25
26
26
preferences : {
You can’t perform that action at this time.
0 commit comments