Skip to content

Commit 9973b9c

Browse files
committed
Add an OmittedExpression for trailing commas in calls
1 parent f28e931 commit 9973b9c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/compiler/parser.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,9 @@ module ts {
12281228
grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed);
12291229
}
12301230
}
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) {
12321234
result.push(<T>createNode(SyntaxKind.OmittedExpression));
12331235
}
12341236
}
@@ -2301,8 +2303,11 @@ module ts {
23012303
else {
23022304
parseExpected(SyntaxKind.OpenParenToken);
23032305
}
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.
23042309
callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions,
2305-
parseAssignmentExpression, /*allowTrailingComma*/ false, /*preserveTrailingComma*/ false);
2310+
parseAssignmentExpression, /*allowTrailingComma*/ false, /*preserveTrailingComma*/ true);
23062311
parseExpected(SyntaxKind.CloseParenToken);
23072312
expr = finishNode(callExpr);
23082313
continue;
@@ -2514,8 +2519,11 @@ module ts {
25142519
parseExpected(SyntaxKind.NewKeyword);
25152520
node.func = parseCallAndAccess(parsePrimaryExpression(), /* inNewExpression */ true);
25162521
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.
25172525
node.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions,
2518-
parseAssignmentExpression, /*allowTrailingComma*/ false, /*preserveTrailingComma*/ false);
2526+
parseAssignmentExpression, /*allowTrailingComma*/ false, /*preserveTrailingComma*/ true);
25192527
parseExpected(SyntaxKind.CloseParenToken);
25202528
}
25212529
return finishNode(node);

0 commit comments

Comments
 (0)