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
Fix: Don't require commas after rest properties (fixes #7297) #7298
Conversation
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mysticatea, @alberto and @gimenete to be potential reviewers. |
LGTM |
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.
LGTM, thanks!
return node.type !== "ArrayPattern" || lastItem.type !== "RestElement"; | ||
return !( | ||
(node.type === "ArrayPattern" && lastItem.type === "RestElement") || | ||
(node.type === "ObjectPattern" && (lastItem.type === "RestProperty" || lastItem.type === "ExperimentalRestProperty")) |
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.
Do we have nodes with the "RestProperty" type in Espree? Or is this for the benefit of other parsers?
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 haven't seen any RestProperty
nodes. I put it there assuming that the name will eventually be RestProperty
rather than ExperimentalRestProperty
once it's no longer experimental.
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'd like to hear others' opinions on this. My preference would be not to do this "just in case" and instead to add it in when that becomes a reality (or, hopefully, remove the support for "ExperimentalRestProperty" and add in "RestProperty"). If this helps with other parsers that support this syntax (since we do, even though it's still stage 3), then I'm not opposed to it.
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.
Incidentally, why does espree add the Experimental
prefix? I can understand the need to mark it as experimental, but I would think that is already accomplished by naming the option experimentalObjectRestSpread
. When the node name eventually does change, it will almost certainly break downstream users, and that seems unnecessary to me. (Each node can only have one type, so this isn't like CSS vendor prefixes where the experimental and final versions can be supported simultaneously.)
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.
RestProperty
is used in Babel and it was added to estree as experimental/ as well estree/estree@6e4d212
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.
Espree uses ExperimentalRestProperty
because the feature was experimental. If there was a change before the proposal was fully added to the specification (which just happened), we had the ability to ensure that rules could target both the old representation and the official versions (RestProperty
). I didn't want people relying on an experimental node without knowing that they were doing so.
When we fully implement the spec, we'll use RestProperty
.
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.
LGTM
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
See #7297
Please check each item to ensure your pull request is ready:
What changes did you make? (Give an overview)
This fixes
comma-dangle
to not require trailing commas after rest properties withexperimentalObjectRestSpread
enabled, since this is a SyntaxError according to the spec.Is there anything you'd like reviewers to focus on?
Nothing in particular.