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 comment duplication for experimental ternaries #15965
base: main
Are you sure you want to change the base?
Fix comment duplication for experimental ternaries #15965
Conversation
}); | ||
if (danglingComments) { | ||
consequentComments.push(danglingComments, hardline); | ||
} |
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 took some time to find the root cause, I think the problem here is we are printing the dangling comments in the consequent
and the consequent
will also print them.
Do you think we can check node type of consequent
instead?
Something like:
const nodesShouldPrintDanglingComments = node =>
node.type === 'ArrayExpression' ||
node.type === 'ObjectExpression'
if (!nodesShouldPrintDanglingComments (node)) {
...
}
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.
This sounds plausible to me fwiw
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 don't have much helpful to say here, but I'm sorry for the bug! I've always found comment handling quite confusing.
Description
Fixes #15875
Checklist
changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨