diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cd9db15c7fa..2133915ba46 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8345,12 +8345,14 @@ module ts { // class C { // foo(x: public){} // Error. // } - if (node.typeName.kind === SyntaxKind.Identifier && (node.typeName).isKeywordInStrictMode) { + if (node.typeName.kind === SyntaxKind.Identifier) { let typeName = 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 && (name).isKeywordInStrictMode) { + if (name && name.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(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(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) || - reportStrictModeGrammarErrorInModule(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 && (node).isKeywordInStrictMode) { + if (node.kind === SyntaxKind.Identifier && isReservedwordInStrictMode(node)) { let nameText = declarationNameToString(node); return grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 171413a19df..2b3c022d45a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 32c289a6d23..07f6c1f526c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 },