File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ namespace ts.refactor {
404404 if ( isInImport ( decl ) ) {
405405 oldImportsNeededByNewFile . add ( symbol ) ;
406406 }
407- else if ( isTopLevelDeclaration ( decl ) && ! movedSymbols . has ( symbol ) ) {
407+ else if ( isTopLevelDeclaration ( decl ) && sourceFileOfTopLevelDeclaration ( decl ) === oldFile && ! movedSymbols . has ( symbol ) ) {
408408 newFileImportsFromOldFile . add ( symbol ) ;
409409 }
410410 }
@@ -546,7 +546,11 @@ namespace ts.refactor {
546546 interface TopLevelVariableDeclaration extends VariableDeclaration { parent : VariableDeclarationList & { parent : VariableStatement ; } ; }
547547 type TopLevelDeclaration = NonVariableTopLevelDeclaration | TopLevelVariableDeclaration ;
548548 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 ;
550554 }
551555
552556 function isTopLevelDeclarationStatement ( node : Node ) : node is TopLevelDeclarationStatement {
Original file line number Diff line number Diff line change 44////import './foo';
55////import { a, b, alreadyUnused } from './other';
66////const p = 0;
7- ////[|const y = p + b;|]
7+ ////[|const y: Date = p + b;|]
88////a; y;
99
1010verify . moveToNewFile ( {
@@ -20,7 +20,7 @@ a; y;`,
2020 "/y.ts" :
2121`import { b } from './other';
2222import { p } from './a';
23- export const y = p + b;` ,
23+ export const y: Date = p + b;` ,
2424 } ,
2525
2626 preferences : {
You can’t perform that action at this time.
0 commit comments