mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Record trailing comma even for incorrectly terminated lists
This commit is contained in:
parent
ab3326f7b7
commit
a79a1d2248
@ -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;
|
||||
|
||||
@ -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");
|
||||
Loading…
x
Reference in New Issue
Block a user