@@ -1008,12 +1008,17 @@ module ts {
1008
1008
switch ( parsingContext ) {
1009
1009
case ParsingContext . SourceElements :
1010
1010
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 ( ) ;
1013
1018
case ParsingContext . BlockStatements :
1014
1019
case ParsingContext . SwitchClauseStatements :
1015
1020
// 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 ( ) ;
1017
1022
case ParsingContext . SwitchClauses :
1018
1023
return token === SyntaxKind . CaseKeyword || token === SyntaxKind . DefaultKeyword ;
1019
1024
case ParsingContext . TypeMembers :
@@ -2754,7 +2759,7 @@ module ts {
2754
2759
if ( token !== SyntaxKind . SemicolonToken &&
2755
2760
token !== SyntaxKind . FunctionKeyword &&
2756
2761
token !== SyntaxKind . ClassKeyword &&
2757
- isStatement ( ) &&
2762
+ isStartOfStatement ( ) &&
2758
2763
! isStartOfExpressionStatement ( ) ) {
2759
2764
// Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations)
2760
2765
//
@@ -3760,11 +3765,11 @@ module ts {
3760
3765
}
3761
3766
}
3762
3767
3763
- function isStatement ( ) : boolean {
3768
+ function isStartOfStatement ( ) : boolean {
3764
3769
return ( getStatementFlags ( ) & StatementFlags . Statement ) !== 0 ;
3765
3770
}
3766
3771
3767
- function isModuleElement ( ) : boolean {
3772
+ function isStartOfModuleElement ( ) : boolean {
3768
3773
return ( getStatementFlags ( ) & StatementFlags . StatementOrModuleElement ) !== 0 ;
3769
3774
}
3770
3775
0 commit comments