Record trailing comma even for incorrectly terminated lists

This commit is contained in:
Jason Freeman 2014-09-30 11:06:03 -07:00
parent ab3326f7b7
commit a79a1d2248
2 changed files with 37 additions and 12 deletions

View File

@ -1226,18 +1226,6 @@ module ts {
error(Diagnostics._0_expected, ",");
}
else if (isListTerminator(kind)) {
// Check if the last token was a comma.
if (commaStart >= 0) {
if (!allowTrailingComma) {
if (file.syntacticErrors.length === errorCountBeforeParsingList) {
// Report a grammar error so we don't affect lookahead
grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed);
}
}
// Always preserve a trailing comma by marking it on the NodeArray
result.hasTrailingComma = true;
}
break;
}
else {
@ -1248,6 +1236,23 @@ module ts {
nextToken();
}
}
// Recording the trailing comma is deliberately done after the previous
// loop, and not just if we see a list terminator. This is because the list
// may have ended incorrectly, but it is still important to know if there
// was a trailing comma.
// Check if the last token was a comma.
if (commaStart >= 0) {
if (!allowTrailingComma) {
if (file.syntacticErrors.length === errorCountBeforeParsingList) {
// Report a grammar error so we don't affect lookahead
grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, Diagnostics.Trailing_comma_not_allowed);
}
}
// Always preserve a trailing comma by marking it on the NodeArray
result.hasTrailingComma = true;
}
result.end = getNodeEnd();
parsingContext = saveParsingContext;
return result;

View File

@ -0,0 +1,20 @@
/// <reference path='fourslash.ts'/>
////declare function f(s: string);
////declare function f(n: number);
////declare function f(s: string, b: boolean);
////declare function f(n: number, b: boolean);
////
////f(1/**/ var
goTo.marker();
verify.signatureHelpCountIs(4);
verify.currentSignatureHelpIs("f(n: number): any");
verify.currentParameterHelpArgumentNameIs("n");
verify.currentParameterSpanIs("n: number");
edit.insert(", ");
verify.signatureHelpCountIs(4);
verify.currentSignatureHelpIs("f(n: number, b: boolean): any");
verify.currentParameterHelpArgumentNameIs("b");
verify.currentParameterSpanIs("b: boolean");