@@ -1878,7 +1878,7 @@ module ts {
1878
1878
}
1879
1879
1880
1880
// Parses a comma-delimited list of elements
1881
- function parseDelimitedList < T extends Node > ( kind : ParsingContext , parseElement : ( ) => T ) : NodeArray < T > {
1881
+ function parseDelimitedList < T extends Node > ( kind : ParsingContext , parseElement : ( ) => T , considerSemicolonAsDelimeter ?: boolean ) : NodeArray < T > {
1882
1882
var saveParsingContext = parsingContext ;
1883
1883
parsingContext |= 1 << kind ;
1884
1884
var result = < NodeArray < T > > [ ] ;
@@ -1892,11 +1892,24 @@ module ts {
1892
1892
if ( parseOptional ( SyntaxKind . CommaToken ) ) {
1893
1893
continue ;
1894
1894
}
1895
+
1895
1896
commaStart = - 1 ; // Back to the state where the last token was not a comma
1896
1897
if ( isListTerminator ( kind ) ) {
1897
1898
break ;
1898
1899
}
1900
+
1901
+ // We didn't get a comma, and the list wasn't terminated, explicitly parse
1902
+ // out a comma so we give a good error message.
1899
1903
parseExpected ( SyntaxKind . CommaToken ) ;
1904
+
1905
+ // If the token was a semicolon, and the caller allows that, then skip it and
1906
+ // continue. This ensures we get back on track and don't result in tons of
1907
+ // parse errors. For example, this can happen when people do things like use
1908
+ // a semicolon to delimit object literal members. Note: we'll have already
1909
+ // reported an error when we called parseExpected above.
1910
+ if ( considerSemicolonAsDelimeter && token === SyntaxKind . SemicolonToken && ! scanner . hasPrecedingLineBreak ( ) ) {
1911
+ nextToken ( ) ;
1912
+ }
1900
1913
continue ;
1901
1914
}
1902
1915
@@ -3598,7 +3611,7 @@ module ts {
3598
3611
node . flags |= NodeFlags . MultiLine ;
3599
3612
}
3600
3613
3601
- node . properties = parseDelimitedList ( ParsingContext . ObjectLiteralMembers , parseObjectLiteralElement ) ;
3614
+ node . properties = parseDelimitedList ( ParsingContext . ObjectLiteralMembers , parseObjectLiteralElement , /*considerSemicolonAsDelimeter:*/ true ) ;
3602
3615
parseExpected ( SyntaxKind . CloseBraceToken ) ;
3603
3616
return finishNode ( node ) ;
3604
3617
}
0 commit comments