Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Jan 19, 2024

Description

Fixes #15875

Checklist

  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@sosukesuzuki sosukesuzuki marked this pull request as ready for review January 21, 2024 03:31
});
if (danglingComments) {
consequentComments.push(danglingComments, hardline);
}
Copy link
Sponsor Member

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)) {
  ...
}

Copy link
Collaborator

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

Copy link
Collaborator

@rattrayalex rattrayalex left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comment duplication with experimental ternaries
3 participants