fix(52852): "Move to a new file" refactoring does not maintain "import type" semantics (#52854)

This commit is contained in:
Oleksandr T 2023-02-21 20:02:00 +02:00 committed by GitHub
parent f0d1eee9b1
commit e1ae30e1ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View File

@ -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:

View 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) { }
`,
},
});

View 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) { }
`,
},
});