@@ -15967,33 +15967,38 @@ namespace ts {
15967
15967
if (forInOrOfStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
15968
15968
const variableList = <VariableDeclarationList>forInOrOfStatement.initializer;
15969
15969
if (!checkGrammarVariableDeclarationList(variableList)) {
15970
- if (variableList.declarations.length > 1) {
15971
- const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
15972
- ? Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
15973
- : Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
15974
- return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
15975
- }
15976
- const firstDeclaration = variableList.declarations[0];
15970
+ const declarations = variableList.declarations;
15977
15971
15978
- // firstDeclaration can be undefined if there is variable declaration in for-of or for-in
15972
+ // declarations.length can be zero if there is an error in variable declaration in for-of or for-in
15979
15973
// See http://www.ecma-international.org/ecma-262/6.0/#sec-for-in-and-for-of-statements for details
15980
15974
// For example:
15981
15975
// var let = 10;
15982
15976
// for (let of [1,2,3]) {} // this is invalid ES6 syntax
15983
15977
// for (let in [1,2,3]) {} // this is invalid ES6 syntax
15984
- if (firstDeclaration) {
15985
- if (firstDeclaration.initializer) {
15986
- const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
15987
- ? Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
15988
- : Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
15989
- return grammarErrorOnNode(firstDeclaration.name, diagnostic);
15990
- }
15991
- if (firstDeclaration.type) {
15992
- const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
15993
- ? Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation
15994
- : Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
15995
- return grammarErrorOnNode(firstDeclaration, diagnostic);
15996
- }
15978
+ // We will then want to skip on grammar checking on variableList declaration
15979
+ if (!declarations.length) {
15980
+ return false;
15981
+ }
15982
+
15983
+ if (declarations.length > 1) {
15984
+ const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
15985
+ ? Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
15986
+ : Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
15987
+ return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
15988
+ }
15989
+ const firstDeclaration = declarations[0];
15990
+
15991
+ if (firstDeclaration.initializer) {
15992
+ const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
15993
+ ? Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
15994
+ : Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
15995
+ return grammarErrorOnNode(firstDeclaration.name, diagnostic);
15996
+ }
15997
+ if (firstDeclaration.type) {
15998
+ const diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement
15999
+ ? Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation
16000
+ : Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
16001
+ return grammarErrorOnNode(firstDeclaration, diagnostic);
15997
16002
}
15998
16003
}
15999
16004
}
0 commit comments