From 380918c4978610ccb9b20c619d7e25ecd8be0e97 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 10 Jun 2015 17:20:51 -0700 Subject: [PATCH] Add comments --- src/compiler/checker.ts | 5 +++++ src/compiler/parser.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1dc8081725..c0c11bce5a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11119,6 +11119,7 @@ module ts { ? Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file : Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module; if (checkGrammarModuleElementContext(node, contextErrorMessage)) { + // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors. return; } @@ -11235,6 +11236,7 @@ module ts { function checkImportDeclaration(node: ImportDeclaration) { if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) { + // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. return; } if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { @@ -11260,6 +11262,7 @@ module ts { function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) { + // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. return; } @@ -11295,6 +11298,7 @@ module ts { function checkExportDeclaration(node: ExportDeclaration) { if (checkGrammarModuleElementContext(node, Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) { + // If we hit an export in an illegal context, just bail out to avoid cascading errors. return; } @@ -11338,6 +11342,7 @@ module ts { function checkExportAssignment(node: ExportAssignment) { if (checkGrammarModuleElementContext(node, Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) { + // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors. return; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 71c53f4488..627893d59e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1770,25 +1770,25 @@ module ts { } function parseRightSideOfDot(allowIdentifierNames: boolean): Identifier { - // Technically a keyword is valid here as all keywords are identifier names. - // However, often we'll encounter this in error situations when the keyword + // Technically a keyword is valid here as all identifiers and keywords are identifier names. + // However, often we'll encounter this in error situations when the identifier or keyword // is actually starting another valid construct. // // So, we check for the following specific case: // // name. - // keyword identifierNameOrKeyword + // identifierOrKeyword identifierNameOrKeyword // // Note: the newlines are important here. For example, if that above code // were rewritten into: // - // name.keyword + // name.identifierOrKeyword // identifierNameOrKeyword // // Then we would consider it valid. That's because ASI would take effect and - // the code would be implicitly: "name.keyword; identifierNameOrKeyword". + // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword". // In the first case though, ASI will not take effect because there is not a - // line terminator after the keyword. + // line terminator after the identifier or keyword. if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) { let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);