Skip to content

Commit d579793

Browse files
author
Andy
authored
moveToNewFile: Fix bug for missing importClause (#24224)
1 parent 75ab60f commit d579793

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/services/refactors/moveToNewFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ namespace ts.refactor {
440440
switch (i.kind) {
441441
case SyntaxKind.ImportDeclaration: {
442442
const clause = i.importClause;
443+
if (!clause) return undefined;
443444
const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined;
444445
const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep);
445446
return defaultImport || namedBindings

tests/cases/fourslash/moveToNewFile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path='fourslash.ts' />
22

33
// @Filename: /a.ts
4+
////import "./foo";
45
////import { a, b, alreadyUnused } from "./other";
56
////const p = 0;
67
////[|const y = p + b;|]
@@ -11,6 +12,7 @@ verify.moveToNewFile({
1112
"/a.ts":
1213
`import { y } from "./y";
1314
15+
import "./foo";
1416
import { a, alreadyUnused } from "./other";
1517
export const p = 0;
1618
a; y;`,

0 commit comments

Comments
 (0)