mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix(52852): "Move to a new file" refactoring does not maintain "import type" semantics (#52854)
This commit is contained in:
parent
f0d1eee9b1
commit
e1ae30e1ab
@ -762,7 +762,7 @@ function filterImport(i: SupportedImport, moduleSpecifier: StringLiteralLike, ke
|
||||
const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined;
|
||||
const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep);
|
||||
return defaultImport || namedBindings
|
||||
? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImport, namedBindings), moduleSpecifier, /*assertClause*/ undefined)
|
||||
? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings), moduleSpecifier, /*assertClause*/ undefined)
|
||||
: undefined;
|
||||
}
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
|
||||
21
tests/cases/fourslash/moveToNewFile_typeImport1.ts
Normal file
21
tests/cases/fourslash/moveToNewFile_typeImport1.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: /a.ts
|
||||
////export interface A {
|
||||
//// x: number;
|
||||
////}
|
||||
|
||||
// @Filename: /b.ts
|
||||
////import type { A } from "./a";
|
||||
////[|function f(a: A) {}|]
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/b.ts": "",
|
||||
"/f.ts":
|
||||
`import type { A } from "./a";
|
||||
|
||||
function f(a: A) { }
|
||||
`,
|
||||
},
|
||||
});
|
||||
21
tests/cases/fourslash/moveToNewFile_typeImport2.ts
Normal file
21
tests/cases/fourslash/moveToNewFile_typeImport2.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: /a.ts
|
||||
////export interface A {
|
||||
//// x: number;
|
||||
////}
|
||||
|
||||
// @Filename: /b.ts
|
||||
////import { type A } from "./a";
|
||||
////[|function f(a: A) {}|]
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/b.ts": "",
|
||||
"/f.ts":
|
||||
`import { type A } from "./a";
|
||||
|
||||
function f(a: A) { }
|
||||
`,
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user