moveToNewFile: Ignore reference to global (#24651) (#24653)

This commit is contained in:
Andy
2018-07-03 15:56:57 -07:00
committed by GitHub
parent e614e857e9
commit b104ab3d17
2 changed files with 8 additions and 4 deletions
+6 -2
View File
@@ -472,7 +472,7 @@ namespace ts.refactor {
if (isInImport(decl)) {
oldImportsNeededByNewFile.add(symbol);
}
else if (isTopLevelDeclaration(decl) && !movedSymbols.has(symbol)) {
else if (isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile && !movedSymbols.has(symbol)) {
newFileImportsFromOldFile.add(symbol);
}
}
@@ -614,7 +614,11 @@ namespace ts.refactor {
interface TopLevelVariableDeclaration extends VariableDeclaration { parent: VariableDeclarationList & { parent: VariableStatement; }; }
type TopLevelDeclaration = NonVariableTopLevelDeclaration | TopLevelVariableDeclaration;
function isTopLevelDeclaration(node: Node): node is TopLevelDeclaration {
return isNonVariableTopLevelDeclaration(node) || isVariableDeclaration(node) && isSourceFile(node.parent.parent.parent);
return isNonVariableTopLevelDeclaration(node) && isSourceFile(node.parent) || isVariableDeclaration(node) && isSourceFile(node.parent.parent.parent);
}
function sourceFileOfTopLevelDeclaration(node: TopLevelDeclaration): Node {
return isVariableDeclaration(node) ? node.parent.parent.parent : node.parent;
}
function isTopLevelDeclarationStatement(node: Node): node is TopLevelDeclarationStatement {
+2 -2
View File
@@ -4,7 +4,7 @@
////import './foo';
////import { a, b, alreadyUnused } from './other';
////const p = 0;
////[|const y = p + b;|]
////[|const y: Date = p + b;|]
////a; y;
verify.moveToNewFile({
@@ -20,7 +20,7 @@ a; y;`,
"/y.ts":
`import { b } from './other';
import { p } from './a';
export const y = p + b;`,
export const y: Date = p + b;`,
},
preferences: {