Skip to content

Commit 4b7d2f2

Browse files
author
Yui T
committed
Address code review
1 parent 1246dca commit 4b7d2f2

18 files changed

Lines changed: 113 additions & 85 deletions

src/compiler/checker.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8345,12 +8345,12 @@ module ts {
83458345
// class C {
83468346
// foo(x: public){} // Error.
83478347
// }
8348-
if (node.typeName.kind === SyntaxKind.Identifier && (<Identifier>node.typeName).strictModeKind) {
8348+
if (node.typeName.kind === SyntaxKind.Identifier && (<Identifier>node.typeName).isKeywordInStrictMode) {
83498349
let typeName = <Identifier>node.typeName;
83508350
let nameText = declarationNameToString(typeName);
8351-
reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText) ||
8352-
reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText) ||
8353-
grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText);
8351+
reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
8352+
reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) ||
8353+
grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText);
83548354
}
83558355
return checkTypeReferenceOrHeritageClauseElement(node);
83568356
}
@@ -11960,7 +11960,7 @@ module ts {
1196011960
let nameBindings = impotClause.namedBindings;
1196111961
if (nameBindings.kind === SyntaxKind.NamespaceImport) {
1196211962
let name = <Identifier>(<NamespaceImport>nameBindings).name;
11963-
if (name.strictModeKind) {
11963+
if (name.isKeywordInStrictMode) {
1196411964
let nameText = declarationNameToString(name);
1196511965
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
1196611966
}
@@ -11969,7 +11969,7 @@ module ts {
1196911969
let reportError = false;
1197011970
for (let element of (<NamedImports>nameBindings).elements) {
1197111971
let name = element.name;
11972-
if (name.strictModeKind) {
11972+
if (name.isKeywordInStrictMode) {
1197311973
let nameText = declarationNameToString(name);
1197411974
reportError = grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
1197511975
}
@@ -11983,7 +11983,7 @@ module ts {
1198311983

1198411984
function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean {
1198511985
let name = node.name;
11986-
if (name && name.kind === SyntaxKind.Identifier && (<Identifier>name).strictModeKind) {
11986+
if (name && name.kind === SyntaxKind.Identifier && (<Identifier>name).isKeywordInStrictMode) {
1198711987
let nameText = declarationNameToString(name);
1198811988
switch (node.kind) {
1198911989
case SyntaxKind.Parameter:
@@ -11994,18 +11994,18 @@ module ts {
1199411994
case SyntaxKind.InterfaceDeclaration:
1199511995
case SyntaxKind.TypeAliasDeclaration:
1199611996
case SyntaxKind.EnumDeclaration:
11997-
let reportError = reportStrictModeGrammarErrorInClassDeclaration(<Identifier>name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText) ||
11998-
reportStrictModeGrammarErrorInModule(<Identifier>name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText) ||
11997+
let reportError = reportStrictModeGrammarErrorInClassDeclaration(<Identifier>name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
11998+
reportStrictModeGrammarErrorInModule(<Identifier>name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) ||
1199911999
grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
1200012000
return reportError ? reportError : false;
1200112001

1200212002
case SyntaxKind.ClassDeclaration:
1200312003
// Report an error if the class declaration uses strict-mode reserved word.
12004-
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode, nameText);
12004+
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText);
1200512005

1200612006
case SyntaxKind.ModuleDeclaration:
1200712007
// Report an error if the module declaration uses strict-mode reserved word.
12008-
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode, nameText);
12008+
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText);
1200912009

1201012010
case SyntaxKind.ImportEqualsDeclaration:
1201112011
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
@@ -12015,7 +12015,7 @@ module ts {
1201512015
}
1201612016

1201712017
function checkGrammarExpressionInStrictMode(node: Expression): boolean {
12018-
if (node.kind === SyntaxKind.Identifier && (<Identifier>node).strictModeKind) {
12018+
if (node.kind === SyntaxKind.Identifier && (<Identifier>node).isKeywordInStrictMode) {
1201912019
let nameText = declarationNameToString(<Identifier>node);
1202012020
return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
1202112021
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ module ts {
170170
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
Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" },
173-
Identifier_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." },
174-
Identifier_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode." },
173+
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
174+
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." },
175175
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
176-
Type_expected_0_is_a_reserved_word_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode." },
177-
Type_expected_0_is_a_reserved_word_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word. Module is automatically in strict mode." },
176+
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
177+
Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." },
178178
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
179179
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." },
180180
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,23 +671,23 @@
671671
"category": "Error",
672672
"code": 1212
673673
},
674-
"Identifier expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": {
674+
"Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode.": {
675675
"category": "Error",
676676
"code": 1213
677677
},
678-
"Identifier expected. '{0}' is a reserved word. Module is automatically in strict mode.": {
678+
"Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode.": {
679679
"category": "Error",
680680
"code": 1214
681681
},
682682
"Type expected. '{0}' is a reserved word in strict mode": {
683683
"category": "Error",
684684
"code": 1215
685685
},
686-
"Type expected. '{0}' is a reserved word. Class definitions are automatically in strict mode.": {
686+
"Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode.": {
687687
"category": "Error",
688688
"code": 1216
689689
},
690-
"Type expected. '{0}' is a reserved word. Module is automatically in strict mode.": {
690+
"Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode.": {
691691
"category": "Error",
692692
"code": 1217
693693
},

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ module ts {
14891489

14901490
// Set strictModeKind property so that we can report appropriate error later in type checker
14911491
if (inStrictModeContext() && (token > SyntaxKind.Identifier && token <= SyntaxKind.LastFutureReservedWord)) {
1492-
node.strictModeKind = token;
1492+
node.isKeywordInStrictMode = token;
14931493
}
14941494
node.text = internIdentifier(scanner.getTokenValue());
14951495
nextToken();

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ module ts {
387387

388388
export interface Identifier extends PrimaryExpression {
389389
text: string; // Text of identifier (with escapes converted to characters)
390-
strictModeKind?: SyntaxKind; // SyntaxKind set when violating strict mode reserved word
390+
isKeywordInStrictMode?: SyntaxKind; // SyntaxKind which get set when violating strict mode reserved word
391391
}
392392

393393
export interface QualifiedName extends Node {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode.
1+
tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode.
22

33

44
==== tests/cases/compiler/constructorStaticParamName.ts (1 errors) ====
@@ -7,6 +7,6 @@ tests/cases/compiler/constructorStaticParamName.ts(4,18): error TS1213: Identifi
77
class test {
88
constructor (static) { }
99
~~~~~~
10-
!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode.
10+
!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode.
1111
}
1212

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode.
1+
tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode.
22

33

44
==== tests/cases/compiler/constructorStaticParamNameErrors.ts (1 errors) ====
@@ -7,5 +7,5 @@ tests/cases/compiler/constructorStaticParamNameErrors.ts(4,18): error TS1213: Id
77
class test {
88
constructor (static) { }
99
~~~~~~
10-
!!! error TS1213: Identifier expected. 'static' is a reserved word. Class definitions are automatically in strict mode.
10+
!!! error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode.
1111
}

0 commit comments

Comments
 (0)