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
Add a better error message for disallowed trailing commas after rest elements in function params #7460
Comments
Hey @simonbuchan! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Checking, MDN says this isn't legal: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas#Trailing_commas_in_functions Note for arrow functions, this gives an explicit error, so it should do the same for
|
I actually ran into this in typescript code, where the editor wasn't complaining, checking,
|
Yep, as you discovered, trailing commas are not allowed in function params after rest elements. The fact that TS allows it may or may not be a bug, @andy-ms could you comment? I'm leaning toward it being an accidental bug in the way it parses function arguments, because TS also appears to allow
but then transforms it into
which is broken. |
@loganfsmyth Made a pull request for trailing comma rest parameters. We already show an error for a non-last rest parameter. |
Perfect, thanks! I'll close this then.
Ahh you're right. I looked at the /play example and saw that the code on the right looked bad, but didn't notice that it also errored out in the typechecker. |
We can't get the nicer arrow function message? That's a lot clearer that it's deliberate. |
Oh sure, I'd be happy to leave this open for that. |
I would like to work on this if no one else is already. |
@loganfsmyth I can handle this. What package is currently handling that error output for the trailing comma ? |
@loganfsmyth fixed in #9046 |
Update
Let's make a nice "A trailing comma is not permitted after the rest element" error for all commas after function params. Currently we throw a nice error for arrow functions in this case, but apparently not for non-arrow functions.
Original Issue below
This is a bug report.
Input Code
Babel/Babylon Configuration (.babelrc, package.json, cli command)
Expected Behavior
Current Behavior
Your Environment
The text was updated successfully, but these errors were encountered: