diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a58b8f052a..527e1bdb1a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8097,6 +8097,14 @@ module ts { } function checkForInStatement(node: ForInStatement) { + // Grammar checking + var declarations = node.declarations; + if (!checkGrammarVariableDeclarations(node, declarations)) { + if (declarations && declarations.length > 1) { + grammarErrorOnFirstToken(declarations[1], Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); + } + } + // TypeScript 1.0 spec (April 2014): 5.4 // In a 'for-in' statement of the form // for (var VarDecl in Expr) Statement @@ -10411,14 +10419,14 @@ module ts { return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } - function checkGrammarVariableDeclarations(variableStatement: VariableStatement, declarations: NodeArray): boolean { + function checkGrammarVariableDeclarations(container: Node, declarations: NodeArray): boolean { if (declarations) { if (checkGrammarForDisallowedTrailingComma(declarations)) { return true; } if (!declarations.length) { - return grammarErrorAtPos(getSourceFileOfNode(variableStatement), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); + return grammarErrorAtPos(getSourceFileOfNode(container), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); } var decl = declarations[0]; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7f73c27532..7e3aff2191 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4644,7 +4644,7 @@ module ts { //case SyntaxKind.ElementAccessExpression: return checkElementAccessExpression(node); //case SyntaxKind.ExportAssignment: return checkExportAssignment(node); //case SyntaxKind.ExternalModuleReference: return checkExternalModuleReference(node); - case SyntaxKind.ForInStatement: return checkForInStatement(node); + //case SyntaxKind.ForInStatement: return checkForInStatement(node); case SyntaxKind.ForStatement: return checkForStatement(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); //case SyntaxKind.FunctionExpression: return checkFunctionExpression(node); diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index d87007474a..c0ae6635c5 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -5,9 +5,9 @@ tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' de tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: 'const' declarations must be initialized -tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. ==== tests/cases/compiler/constDeclarations-errors.ts (10 errors) ==== diff --git a/tests/baselines/reference/declareAlreadySeen.errors.txt b/tests/baselines/reference/declareAlreadySeen.errors.txt index d606b57147..60cd204c40 100644 --- a/tests/baselines/reference/declareAlreadySeen.errors.txt +++ b/tests/baselines/reference/declareAlreadySeen.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/declareAlreadySeen.ts(2,13): error TS1030: 'declare' modifier already seen. tests/cases/compiler/declareAlreadySeen.ts(3,13): error TS1030: 'declare' modifier already seen. tests/cases/compiler/declareAlreadySeen.ts(5,13): error TS1030: 'declare' modifier already seen. +tests/cases/compiler/declareAlreadySeen.ts(2,13): error TS1030: 'declare' modifier already seen. tests/cases/compiler/declareAlreadySeen.ts(7,13): error TS1030: 'declare' modifier already seen. diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt index 19551e9fad..824e36e279 100644 --- a/tests/baselines/reference/letDeclarations-es5.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -1,4 +1,3 @@ -tests/cases/compiler/letDeclarations-es5.ts(10,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(12,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(3,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. @@ -6,6 +5,7 @@ tests/cases/compiler/letDeclarations-es5.ts(4,5): error TS1153: 'let' declaratio tests/cases/compiler/letDeclarations-es5.ts(6,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(7,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/letDeclarations-es5.ts(8,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(10,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. ==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== diff --git a/tests/baselines/reference/parserForInStatement7.errors.txt b/tests/baselines/reference/parserForInStatement7.errors.txt index 2371b3453c..397401003d 100644 --- a/tests/baselines/reference/parserForInStatement7.errors.txt +++ b/tests/baselines/reference/parserForInStatement7.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,25): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,10): error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. +tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,25): error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts(1,43): error TS2304: Cannot find name 'X'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts (3 errors) ==== for (var a: number = 1, b: string = "" in X) { - ~ -!!! error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. ~ !!! error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. + ~ +!!! error TS1091: Only a single variable declaration is allowed in a 'for...in' statement. ~ !!! error TS2304: Cannot find name 'X'. } \ No newline at end of file