@@ -1228,7 +1228,9 @@ module ts {
1228
1228
grammarErrorAtPos ( commaStart , scanner . getStartPos ( ) - commaStart , Diagnostics . Trailing_comma_not_allowed ) ;
1229
1229
}
1230
1230
}
1231
- else if ( preserveTrailingComma ) {
1231
+ // Even if we reported an error because of a disallowed trailing comma, we still may
1232
+ // need to preserve it for the checker so that signature help can work well.
1233
+ if ( preserveTrailingComma ) {
1232
1234
result . push ( < T > createNode ( SyntaxKind . OmittedExpression ) ) ;
1233
1235
}
1234
1236
}
@@ -2301,8 +2303,11 @@ module ts {
2301
2303
else {
2302
2304
parseExpected ( SyntaxKind . OpenParenToken ) ;
2303
2305
}
2306
+ // It is an error to have a trailing comma in an argument list. However, the checker
2307
+ // needs evidence of a trailing comma in order to give good results for signature help.
2308
+ // That is why we do not allow a trailing comma, but we "preserve" a trailing comma.
2304
2309
callExpr . arguments = parseDelimitedList ( ParsingContext . ArgumentExpressions ,
2305
- parseAssignmentExpression , /*allowTrailingComma*/ false , /*preserveTrailingComma*/ false ) ;
2310
+ parseAssignmentExpression , /*allowTrailingComma*/ false , /*preserveTrailingComma*/ true ) ;
2306
2311
parseExpected ( SyntaxKind . CloseParenToken ) ;
2307
2312
expr = finishNode ( callExpr ) ;
2308
2313
continue ;
@@ -2514,8 +2519,11 @@ module ts {
2514
2519
parseExpected ( SyntaxKind . NewKeyword ) ;
2515
2520
node . func = parseCallAndAccess ( parsePrimaryExpression ( ) , /* inNewExpression */ true ) ;
2516
2521
if ( parseOptional ( SyntaxKind . OpenParenToken ) || token === SyntaxKind . LessThanToken && ( node . typeArguments = tryParse ( parseTypeArgumentsAndOpenParen ) ) ) {
2522
+ // It is an error to have a trailing comma in an argument list. However, the checker
2523
+ // needs evidence of a trailing comma in order to give good results for signature help.
2524
+ // That is why we do not allow a trailing comma, but we "preserve" a trailing comma.
2517
2525
node . arguments = parseDelimitedList ( ParsingContext . ArgumentExpressions ,
2518
- parseAssignmentExpression , /*allowTrailingComma*/ false , /*preserveTrailingComma*/ false ) ;
2526
+ parseAssignmentExpression , /*allowTrailingComma*/ false , /*preserveTrailingComma*/ true ) ;
2519
2527
parseExpected ( SyntaxKind . CloseParenToken ) ;
2520
2528
}
2521
2529
return finishNode ( node ) ;
0 commit comments