-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on rest parameter with trailing comma #22262
Conversation
TSLint's There's an option to forbid trailing commas in that position, but it's not enabled by default. That means this change will break a lot of projects. |
Not to put too fine a point on it, but we're not responsible for projects enforcing that they have a syntax error, even if we mistakenly didn't flag that error |
It looks like the same issue is present for array rest and object rest.
also passes without error. |
And not only on binding patterns, but also in destructuring assignments: ({...foo,} = {});
[...bar,] = []; |
src/compiler/checker.ts
Outdated
@@ -26093,6 +26093,9 @@ namespace ts { | |||
if (i !== (parameterCount - 1)) { | |||
return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); | |||
} | |||
if (parameters.hasTrailingComma) { | |||
return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.A_rest_parameter_may_not_have_a_trailing_comma); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that this is the wrong span to error on. Either error on the comma, or the parameter itself.
3f3b9f3
to
f69d5b4
Compare
Noticed that tslint has a |
@@ -26067,11 +26069,9 @@ namespace ts { | |||
return grammarErrorOnNode(asyncModifier, Diagnostics._0_modifier_cannot_be_used_here, "async"); | |||
} | |||
|
|||
function checkGrammarForDisallowedTrailingComma(list: NodeArray<Node>): boolean { | |||
function checkGrammarForDisallowedTrailingComma(list: NodeArray<Node>, diag = Diagnostics.Trailing_comma_not_allowed): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this optional parameter used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the four new calls added in this PR.
@andy-ms please add a blurb about this change in https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes |
@mhegazy Good to merge now that 2.8 is released? |
👍 |
@ajafff I run into this issue with
After some search, I did not find the option you mentioned, would be appreciate if you could post it here, thanks! |
Since TS v2.9 trailing comma is not allowed after rest parameters or bindings. See: microsoft/TypeScript#22262 This PR is just aligning with new TS requirement to avoid conflicts.
Fixes babel/babel#7460 (comment)
This will likely be annoying for many users, so we should make sure this definitely isn't going to be allowed by any future ES spec.
(MDN ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas#Trailing_commas_in_functions)