Skip to content

Commit 380918c

Browse files
committed
Add comments
1 parent d03fca2 commit 380918c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11119,6 +11119,7 @@ module ts {
1111911119
? Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
1112011120
: Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
1112111121
if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
11122+
// If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
1112211123
return;
1112311124
}
1112411125

@@ -11235,6 +11236,7 @@ module ts {
1123511236

1123611237
function checkImportDeclaration(node: ImportDeclaration) {
1123711238
if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
11239+
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
1123811240
return;
1123911241
}
1124011242
if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
@@ -11260,6 +11262,7 @@ module ts {
1126011262

1126111263
function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) {
1126211264
if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
11265+
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
1126311266
return;
1126411267
}
1126511268

@@ -11295,6 +11298,7 @@ module ts {
1129511298

1129611299
function checkExportDeclaration(node: ExportDeclaration) {
1129711300
if (checkGrammarModuleElementContext(node, Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
11301+
// If we hit an export in an illegal context, just bail out to avoid cascading errors.
1129811302
return;
1129911303
}
1130011304

@@ -11338,6 +11342,7 @@ module ts {
1133811342

1133911343
function checkExportAssignment(node: ExportAssignment) {
1134011344
if (checkGrammarModuleElementContext(node, Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
11345+
// If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
1134111346
return;
1134211347
}
1134311348

src/compiler/parser.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,25 +1770,25 @@ module ts {
17701770
}
17711771

17721772
function parseRightSideOfDot(allowIdentifierNames: boolean): Identifier {
1773-
// Technically a keyword is valid here as all keywords are identifier names.
1774-
// However, often we'll encounter this in error situations when the keyword
1773+
// Technically a keyword is valid here as all identifiers and keywords are identifier names.
1774+
// However, often we'll encounter this in error situations when the identifier or keyword
17751775
// is actually starting another valid construct.
17761776
//
17771777
// So, we check for the following specific case:
17781778
//
17791779
// name.
1780-
// keyword identifierNameOrKeyword
1780+
// identifierOrKeyword identifierNameOrKeyword
17811781
//
17821782
// Note: the newlines are important here. For example, if that above code
17831783
// were rewritten into:
17841784
//
1785-
// name.keyword
1785+
// name.identifierOrKeyword
17861786
// identifierNameOrKeyword
17871787
//
17881788
// Then we would consider it valid. That's because ASI would take effect and
1789-
// the code would be implicitly: "name.keyword; identifierNameOrKeyword".
1789+
// the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword".
17901790
// In the first case though, ASI will not take effect because there is not a
1791-
// line terminator after the keyword.
1791+
// line terminator after the identifier or keyword.
17921792
if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
17931793
let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
17941794

0 commit comments

Comments
 (0)