Disallow type annotation on a for-of variable
This commit is contained in:
parent
147cc204b8
commit
7cb2a64350
|
@ -8467,9 +8467,6 @@ module ts {
|
|||
if (variableDeclarationList.declarations.length >= 1) {
|
||||
var decl = variableDeclarationList.declarations[0];
|
||||
checkVariableDeclaration(decl);
|
||||
if (decl.type) {
|
||||
error(decl, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -10769,11 +10766,18 @@ module ts {
|
|||
Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
|
||||
return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
|
||||
}
|
||||
if (variableList.declarations[0].initializer) {
|
||||
var firstDeclaration = variableList.declarations[0];
|
||||
if (firstDeclaration.initializer) {
|
||||
var diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement ?
|
||||
Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer :
|
||||
Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
|
||||
return grammarErrorOnNode(variableList.declarations[0].name, diagnostic);
|
||||
return grammarErrorOnNode(firstDeclaration.name, diagnostic);
|
||||
}
|
||||
if (firstDeclaration.type) {
|
||||
var diagnostic = forInOrOfStatement.kind === SyntaxKind.ForInStatement ?
|
||||
Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation :
|
||||
Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
|
||||
return grammarErrorOnNode(firstDeclaration, diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -317,6 +317,7 @@ module ts {
|
|||
let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 2476, category: DiagnosticCategory.Error, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." },
|
||||
Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 2477, category: DiagnosticCategory.Error, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." },
|
||||
For_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 2482, category: DiagnosticCategory.Error, key: "For-of statements are only available when targeting ECMAScript 6 or higher" },
|
||||
The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
|
|
|
@ -1260,6 +1260,10 @@
|
|||
"category": "Error",
|
||||
"code": 2482
|
||||
},
|
||||
"The left-hand side of a 'for...of' statement cannot use a type annotation.": {
|
||||
"category": "Error",
|
||||
"code": 2483
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement5.ts(1,1): error TS2482: For-of statements are only available when targeting ECMAScript 6 or higher
|
||||
tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement5.ts(1,10): error TS2483: The left-hand side of a 'for...of' statement cannot use a type annotation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement5.ts (1 errors) ====
|
||||
for (var a: number of X) {
|
||||
~~~
|
||||
!!! error TS2482: For-of statements are only available when targeting ECMAScript 6 or higher
|
||||
~
|
||||
!!! error TS2483: The left-hand side of a 'for...of' statement cannot use a type annotation.
|
||||
}
|
|
@ -1,12 +1,9 @@
|
|||
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) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts (2 errors) ====
|
||||
for (var a: number = 1, b: string = "" in X) {
|
||||
~
|
||||
!!! 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.
|
||||
~
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts(1,10): error TS2483: The left-hand side of a 'for...of' statement cannot use a type annotation.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement5.ts (1 errors) ====
|
||||
for (var a: number of X) {
|
||||
~
|
||||
!!! error TS2483: The left-hand side of a 'for...of' statement cannot use a type annotation.
|
||||
}
|
Loading…
Reference in a new issue