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
Version 3.8.0 comma-dangle breaks Flowtype annotations when a object rest parameter is used #7370
Comments
For what it's worth, I think your syntax is invalid based on the current version of the rest/spread spec; trailing commas aren't allowed after rest properties, since no property could actually be added after it. (See #7297 for more info.) class Foo {
constructor ({
bar,
...baz, // <-- trailing comma is not allowed here according to rest/spread spec
}) {}
} Does the problem go away if you remove that comma? |
You're right about the comma after spread, but the comma dangle error persists even after removing it. |
Thanks for the fast response and fix 👍🏻 |
Yes, I can confirm this is an issue when upgrading to v3.8.0. Here is a much simpler repro example:
Let me know if you need my eslint config for this. |
Oh, I see. I believe my syntax is valid for Stage 3 of ECMAScript and is handled for us by Babel. We use ESLint with some newer ECMAScript proposed features such as this (specifically we use the same ES feature set as ReactNative.) It has been working as long as I can remember but broke when upgrading from 3.7.1 to 3.8.0 (presumably because of the bugfix you referenced). I am sticking to 3.7.1 now but probably need a way forward with proposed, not-yet-standardized features. |
I understand that you're using babel, but a trailing comma after a rest property is not valid syntax even according to the current proposal spec, because there is nothing that could follow a rest property. The same thing applies with the already-standardized rest elements: const [
foo,
...bar, // <-- This is a syntax error in ES6
] = baz; In order to be more compliant with the spec, babel's parser temporarily reported this as a syntax error, but it was later reverted due to breakage. The fix in this case is to simply remove the comma, so that it becomes valid syntax according to the Stage 3 proposal. |
Oh, I see! This I did not know! So Babel is being more liberal than the standards in what it accepts. Interesting. Thank you for taking the time to explain this. I wonder how to get the word out there so people don't continue opening issues.. |
Tell us about your environment
v3.8.0
v6.7.0
3.10.3
What parser (default, Babel-ESLint, etc.) are you using?
Babel-ESLint
Please show your full configuration:
.eslintrc.js
.babelrc
What did you do? Please include the actual source code causing the issue.
I created a "minimal" demo to reproduce the problem. My impression is that since 3.8.0 (it works on 3.7.1) comma-dangle (set to always-multiline) reports a comma in a flow annotation when a object rest parameter is used before.
Complete demo code:
https://gist.github.com/mormahr/e6af53438a9bae9b9fe8905cc938b77d
What did you expect to happen?
No report of an unexpected comma
What actually happened? Please include the actual, raw output from ESLint.
[PRIVATE]/CommaDangleBug/test.js
9:14 error Unexpected trailing comma comma-dangle
✖ 1 problem (1 error, 0 warnings)
The text was updated successfully, but these errors were encountered: