Skip to content

Commit e1ae30e

Browse files
authored
fix(52852): "Move to a new file" refactoring does not maintain "import type" semantics (#52854)
1 parent f0d1eee commit e1ae30e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/services/refactors/moveToNewFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ function filterImport(i: SupportedImport, moduleSpecifier: StringLiteralLike, ke
762762
const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined;
763763
const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep);
764764
return defaultImport || namedBindings
765-
? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImport, namedBindings), moduleSpecifier, /*assertClause*/ undefined)
765+
? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings), moduleSpecifier, /*assertClause*/ undefined)
766766
: undefined;
767767
}
768768
case SyntaxKind.ImportEqualsDeclaration:
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: /a.ts
4+
////export interface A {
5+
//// x: number;
6+
////}
7+
8+
// @Filename: /b.ts
9+
////import type { A } from "./a";
10+
////[|function f(a: A) {}|]
11+
12+
verify.moveToNewFile({
13+
newFileContents: {
14+
"/b.ts": "",
15+
"/f.ts":
16+
`import type { A } from "./a";
17+
18+
function f(a: A) { }
19+
`,
20+
},
21+
});
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: /a.ts
4+
////export interface A {
5+
//// x: number;
6+
////}
7+
8+
// @Filename: /b.ts
9+
////import { type A } from "./a";
10+
////[|function f(a: A) {}|]
11+
12+
verify.moveToNewFile({
13+
newFileContents: {
14+
"/b.ts": "",
15+
"/f.ts":
16+
`import { type A } from "./a";
17+
18+
function f(a: A) { }
19+
`,
20+
},
21+
});

0 commit comments

Comments
 (0)