Skip to content

Commit c09cc70

Browse files
author
Andy
authored
Fix bug: VariableDeclaration initializer may be undefined (microsoft#24256)
1 parent 153c180 commit c09cc70

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/services/refactors/moveToNewFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace ts.refactor {
7676
case SyntaxKind.ImportEqualsDeclaration:
7777
return !hasModifier(node, ModifierFlags.Export);
7878
case SyntaxKind.VariableStatement:
79-
return (node as VariableStatement).declarationList.declarations.every(d => isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true));
79+
return (node as VariableStatement).declarationList.declarations.every(d => d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true));
8080
default:
8181
return false;
8282
}

tests/cases/fourslash/moveToNewFile_moveImport.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// @Filename: /a.ts
44
////[|import { a, b } from "m";
5+
////let l;
56
////a;|]
67
////b;
78

@@ -10,8 +11,9 @@ verify.moveToNewFile({
1011
"/a.ts":
1112
`import { b } from "m";
1213
b;`,
13-
"/newFile.ts":
14+
"/l.ts":
1415
`import { a } from "m";
16+
let l;
1517
a;`,
1618
}
1719
});

0 commit comments

Comments
 (0)