Skip to content

Commit 83fb930

Browse files
committed
adding fix and tests
1 parent f511ed4 commit 83fb930

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/services/refactors/moveToFile.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ export function getExistingLocals(sourceFile: SourceFile, statements: readonly S
11481148
if (symbol.valueDeclaration && getSourceFileOfNode(symbol.valueDeclaration).path === sourceFile.path) {
11491149
existingLocals.add(symbol);
11501150
}
1151+
else if (!symbol.valueDeclaration && symbol.parent?.valueDeclaration && getSourceFileOfNode(symbol.parent.valueDeclaration).path === sourceFile.path) {
1152+
existingLocals.add(symbol);
1153+
}
11511154
});
11521155
}
11531156
return existingLocals;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: /b.ts
4+
////import { ISomething } from './a';
5+
////
6+
////export function [|func|](something: ISomething) {
7+
////}
8+
9+
// @Filename: /a.ts
10+
////export interface ISomething {
11+
////}
12+
13+
verify.moveToFile({
14+
newFileContents: {
15+
"/a.ts": `export interface ISomething {
16+
}
17+
export function func(something: ISomething) {
18+
}
19+
`,
20+
21+
"/b.ts": `
22+
`,
23+
},
24+
interactiveRefactorArguments: { targetFile: "/a.ts" }
25+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//@Filename: /b.ts
4+
////export type BaseTest = string;
5+
6+
// @Filename: /a.ts
7+
////import { BaseTest } from "./b";
8+
////
9+
////export type [|Test|] = BaseTest;
10+
11+
verify.moveToFile({
12+
newFileContents: {
13+
"/b.ts": `export type BaseTest = string;
14+
export type Test = BaseTest;
15+
`,
16+
17+
"/a.ts": `
18+
`,
19+
},
20+
interactiveRefactorArguments: { targetFile: "/b.ts" }
21+
});

0 commit comments

Comments
 (0)