Fix bug: VariableDeclaration initializer may be undefined (#24256)

This commit is contained in:
Andy 2018-05-21 07:58:33 -07:00 committed by GitHub
parent 153c1806d3
commit c09cc70ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -76,7 +76,7 @@ namespace ts.refactor {
case SyntaxKind.ImportEqualsDeclaration:
return !hasModifier(node, ModifierFlags.Export);
case SyntaxKind.VariableStatement:
return (node as VariableStatement).declarationList.declarations.every(d => isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true));
return (node as VariableStatement).declarationList.declarations.every(d => d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true));
default:
return false;
}

View File

@ -2,6 +2,7 @@
// @Filename: /a.ts
////[|import { a, b } from "m";
////let l;
////a;|]
////b;
@ -10,8 +11,9 @@ verify.moveToNewFile({
"/a.ts":
`import { b } from "m";
b;`,
"/newFile.ts":
"/l.ts":
`import { a } from "m";
let l;
a;`,
}
});