Address code review: have more explicit error

This commit is contained in:
Yui T
2015-04-02 17:42:24 -07:00
parent 696e6a30fc
commit aef37f1e41
7 changed files with 110 additions and 97 deletions
+9 -1
View File
@@ -12441,7 +12441,15 @@ module ts {
let identifier = <Identifier>name;
if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) {
let nameText = declarationNameToString(identifier);
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText);
// We are checking if this parameter's name is of method or constructor so that we can give more explicit errors because
// invalid usage error particularly of "arguments" is very common mistake
if (contextNode && (contextNode.parent.kind === SyntaxKind.MethodDeclaration || contextNode.parent.kind === SyntaxKind.Constructor)) {
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code, nameText);
}
else {
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText);
}
}
}
}
@@ -167,6 +167,7 @@ module ts {
Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." },
Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." },
Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." },
Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}' because class definition is considered a strict mode code " },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
+4
View File
@@ -659,6 +659,10 @@
"category": "Error",
"code": 1209
},
"Invalid use of '{0}' because class definition is considered a strict mode code ": {
"category": "Error",
"code": 1210
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300