Skip to content

Commit 09b9ec4

Browse files
author
Andy
authored
moveToNewFile: Fix bug for VariableDeclaration missing initializer (microsoft#24214)
1 parent a9660f3 commit 09b9ec4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/services/refactors/moveToNewFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ namespace ts.refactor {
433433
}
434434
function isVariableDeclarationInImport(decl: VariableDeclaration) {
435435
return isSourceFile(decl.parent.parent.parent) &&
436-
isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
436+
decl.initializer && isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
437437
}
438438

439439
function filterImport(i: SupportedImport, moduleSpecifier: StringLiteralLike, keep: (name: Identifier) => boolean): SupportedImportStatement | undefined {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
////export {};
5+
////let x;
6+
////[|const y = x;|]
7+
8+
verify.moveToNewFile({
9+
newFileContents: {
10+
"/a.ts":
11+
`export {};
12+
export let x;
13+
`,
14+
15+
"/y.ts":
16+
`import { x } from "./a";
17+
const y = x;`,
18+
},
19+
});

0 commit comments

Comments
 (0)