Skip to content

Commit 26b955a

Browse files
committed
Addressing more CR feedback
1 parent b28f74e commit 26b955a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/compiler/parser.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,17 @@ module ts {
10081008
switch (parsingContext) {
10091009
case ParsingContext.SourceElements:
10101010
case ParsingContext.ModuleElements:
1011-
// During error recovery we don't treat empty statements as statements
1012-
return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isModuleElement();
1011+
// If we're in error recovery, then we don't want to treat ';' as an empty statement.
1012+
// The problem is that ';' can show up in far too many contexts, and if we see one
1013+
// and assume it's a statement, then we may bail out inappropriately from whatever
1014+
// we're parsing. For example, if we have a semicolon in the middle of a class, then
1015+
// we really don't want to assume the class is over and we're on a statement in the
1016+
// outer module. We just want to consume and move on.
1017+
return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfModuleElement();
10131018
case ParsingContext.BlockStatements:
10141019
case ParsingContext.SwitchClauseStatements:
10151020
// During error recovery we don't treat empty statements as statements
1016-
return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStatement();
1021+
return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement();
10171022
case ParsingContext.SwitchClauses:
10181023
return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword;
10191024
case ParsingContext.TypeMembers:
@@ -2754,7 +2759,7 @@ module ts {
27542759
if (token !== SyntaxKind.SemicolonToken &&
27552760
token !== SyntaxKind.FunctionKeyword &&
27562761
token !== SyntaxKind.ClassKeyword &&
2757-
isStatement() &&
2762+
isStartOfStatement() &&
27582763
!isStartOfExpressionStatement()) {
27592764
// Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations)
27602765
//
@@ -3760,11 +3765,11 @@ module ts {
37603765
}
37613766
}
37623767

3763-
function isStatement(): boolean {
3768+
function isStartOfStatement(): boolean {
37643769
return (getStatementFlags() & StatementFlags.Statement) !== 0;
37653770
}
37663771

3767-
function isModuleElement(): boolean {
3772+
function isStartOfModuleElement(): boolean {
37683773
return (getStatementFlags() & StatementFlags.StatementOrModuleElement) !== 0;
37693774
}
37703775

0 commit comments

Comments
 (0)