Skip to content

Commit 09d037f

Browse files
author
Yui T
committed
Address code review
1 parent 4824e96 commit 09d037f

7 files changed

+141
-140
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12446,10 +12446,11 @@ module ts {
1244612446
if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) {
1244712447
let nameText = declarationNameToString(identifier);
1244812448

12449-
// We are checking if this parameter's name is of method or constructor so that we can give more explicit errors because
12450-
// invalid usage error particularly of "arguments" is very common mistake
12451-
if (contextNode && (contextNode.parent.kind === SyntaxKind.MethodDeclaration || contextNode.parent.kind === SyntaxKind.Constructor)) {
12452-
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_because_class_definition_is_considered_a_strict_mode_code, nameText);
12449+
// We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.)
12450+
// if so, we would like to give more explicit invalid usage error.
12451+
// This will be particularly helpful in the case of "arguments" as such case is very common mistake.
12452+
if (getAncestor(name, SyntaxKind.ClassDeclaration) || getAncestor(name, SyntaxKind.ClassExpression)) {
12453+
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText);
1245312454
}
1245412455
else {
1245512456
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText);

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module ts {
167167
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." },
168168
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." },
169169
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." },
170-
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 " },
170+
Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." },
171171
A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" },
172172
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
173173
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." },

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@
659659
"category": "Error",
660660
"code": 1209
661661
},
662-
"Invalid use of '{0}' because class definition is considered a strict mode code ": {
662+
"Invalid use of '{0}'. Class definitions are automatically in strict mode.": {
663663
"category": "Error",
664664
"code": 1210
665665
},

0 commit comments

Comments
 (0)