Addresses CR feedback

This commit is contained in:
Tingan Ho
2015-06-08 11:41:08 +08:00
parent b1a8a5fe66
commit 51a43dd9d5
7 changed files with 62 additions and 33 deletions

View File

@@ -8649,21 +8649,31 @@ module ts {
}
else if (typePredicateNode.parameterName) {
let hasReportedError = false;
outer: for (let param of node.parameters) {
for (var param of node.parameters) {
if (hasReportedError) {
break;
}
if (param.name.kind === SyntaxKind.ObjectBindingPattern ||
param.name.kind === SyntaxKind.ArrayBindingPattern) {
for (let element of (<BindingPattern>param.name).elements) {
if (element.name.kind === SyntaxKind.Identifier &&
(<Identifier>element.name).text === typePredicateNode.parameterName.text) {
error(typePredicateNode.parameterName,
Diagnostics.Type_predicate_cannot_reference_element_0_in_a_binding_pattern,
typePredicate.parameterName);
hasReportedError = true;
break outer;
(function checkBindingPattern(elements: NodeArray<BindingElement>) {
for (let element of elements) {
if (element.name.kind === SyntaxKind.Identifier &&
(<Identifier>element.name).text === typePredicate.parameterName) {
error(typePredicateNode.parameterName,
Diagnostics.Type_predicate_cannot_reference_element_0_in_a_binding_pattern,
typePredicate.parameterName);
hasReportedError = true;
break;
}
else if(element.name.kind === SyntaxKind.ArrayBindingPattern ||
element.name.kind === SyntaxKind.ObjectBindingPattern) {
checkBindingPattern((<BindingPattern>element.name).elements);
}
}
}
})((<BindingPattern>param.name).elements);
}
}
if (!hasReportedError) {
@@ -8675,7 +8685,7 @@ module ts {
}
else {
error(typePredicateNode,
Diagnostics.Type_predicates_are_only_allowed_in_return_type_position_for_functions_and_methods);
Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods);
}
}
else {
@@ -11317,7 +11327,7 @@ module ts {
function checkTypePredicate(node: TypePredicateNode) {
if(!isInLegalTypePredicatePosition(node)) {
error(node, Diagnostics.Type_predicates_are_only_allowed_in_return_type_position_for_functions_and_methods);
error(node, Diagnostics.Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods);
}
}

View File

@@ -183,7 +183,7 @@ module ts {
Cannot_find_parameter_0: { code: 1225, category: DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." },
Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." },
Parameter_0_is_not_in_the_same_position_as_parameter_1: { code: 1227, category: DiagnosticCategory.Error, key: "Parameter '{0}' is not in the same position as parameter '{1}'." },
Type_predicates_are_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "Type predicates are only allowed in return type position for functions and methods." },
Type_predicate_are_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: DiagnosticCategory.Error, key: "Type predicate are only allowed in return type position for functions and methods." },
Type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: DiagnosticCategory.Error, key: "Type predicate cannot reference a rest parameter." },
Type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: DiagnosticCategory.Error, key: "Type predicate cannot reference element '{0}' in a binding pattern." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },

View File

@@ -719,7 +719,7 @@
"category": "Error",
"code": 1227
},
"Type predicates are only allowed in return type position for functions and methods.": {
"Type predicate are only allowed in return type position for functions and methods.": {
"category": "Error",
"code": 1228
},