Remove incorrect check of module declartion

This commit is contained in:
Yui T
2015-04-09 15:58:56 -07:00
parent e91ef844ed
commit 8771212d58
3 changed files with 22 additions and 21 deletions
+20 -19
View File
@@ -8345,12 +8345,14 @@ module ts {
// class C {
// foo(x: public){} // Error.
// }
if (node.typeName.kind === SyntaxKind.Identifier && (<Identifier>node.typeName).isKeywordInStrictMode) {
if (node.typeName.kind === SyntaxKind.Identifier) {
let typeName = <Identifier>node.typeName;
let nameText = declarationNameToString(typeName);
reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
reportStrictModeGrammarErrorInModule(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) ||
grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText);
if (isReservedwordInStrictMode(typeName)) {
let nameText = declarationNameToString(typeName);
// TODO(yuisu): Fix this when external module becomes strict mode code;
reportStrictModeGrammarErrorInClassDeclaration(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
grammarErrorOnNode(typeName, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText);
}
}
return checkTypeReferenceOrHeritageClauseElement(node);
}
@@ -11932,8 +11934,14 @@ module ts {
anyArrayType = createArrayType(anyType);
}
// GRAMMAR CHECKING
function isReservedwordInStrictMode(node: Identifier): boolean {
if ((node.parserContextFlags & ParserContextFlags.StrictMode) && node.isKeywordInStrictMode) {
return true;
}
return false
}
function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
// We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.)
// if so, we would like to give more explicit invalid usage error.
@@ -11943,15 +11951,6 @@ module ts {
return false;
}
function reportStrictModeGrammarErrorInModule(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
// We are checking if this name is inside module declaration which is automatically a strict mode code in ES6.
// If so, we would like to give more explicit invalid usage error.
if (getAncestor(identifier, SyntaxKind.ModuleDeclaration)) {
return grammarErrorOnNode(identifier, message, arg0);
}
return false;
}
function checkGrammarImportDeclarationNameInStrictMode(node: ImportDeclaration): boolean {
// Check if the import declaration used strict-mode reserved word in its names bindings
if (node.importClause) {
@@ -11983,7 +11982,7 @@ module ts {
function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean {
let name = node.name;
if (name && name.kind === SyntaxKind.Identifier && (<Identifier>name).isKeywordInStrictMode) {
if (name && name.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(<Identifier>name)) {
let nameText = declarationNameToString(name);
switch (node.kind) {
case SyntaxKind.Parameter:
@@ -11994,8 +11993,8 @@ module ts {
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.EnumDeclaration:
// TODO(yuisu): fix this when having external moduel in strict mode
let reportError = reportStrictModeGrammarErrorInClassDeclaration(<Identifier>name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
reportStrictModeGrammarErrorInModule(<Identifier>name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText) ||
grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
return reportError ? reportError : false;
@@ -12005,9 +12004,11 @@ module ts {
case SyntaxKind.ModuleDeclaration:
// Report an error if the module declaration uses strict-mode reserved word.
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode, nameText);
// TODO(yuisu): fix this when having external module in strict mode
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
case SyntaxKind.ImportEqualsDeclaration:
// TODO(yuisu): fix this when having external moduel in strict mode
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
}
}
@@ -12015,7 +12016,7 @@ module ts {
}
function checkGrammarExpressionInStrictMode(node: Expression): boolean {
if (node.kind === SyntaxKind.Identifier && (<Identifier>node).isKeywordInStrictMode) {
if (node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(<Identifier>node)) {
let nameText = declarationNameToString(<Identifier>node);
return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
}
@@ -171,7 +171,7 @@ module ts {
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" },
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" },
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." },
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." },
Identifier_expected_0_is_a_reserved_word_in_strict_mode_External_Module_is_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode." },
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" },
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." },
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." },
+1 -1
View File
@@ -675,7 +675,7 @@
"category": "Error",
"code": 1213
},
"Identifier expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode.": {
"Identifier expected. '{0}' is a reserved word in strict mode. External Module is automatically in strict mode.": {
"category": "Error",
"code": 1214
},