diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b06326f6925..f67873c2c40 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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; diff --git a/tests/cases/fourslash/signatureHelpOnOverloadsDifferentArity2.ts b/tests/cases/fourslash/signatureHelpOnOverloadsDifferentArity2.ts new file mode 100644 index 00000000000..1f87f3b9a0c --- /dev/null +++ b/tests/cases/fourslash/signatureHelpOnOverloadsDifferentArity2.ts @@ -0,0 +1,20 @@ +/// + +////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"); \ No newline at end of file