Skip to content

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Jan 1, 2022

Description

Fixes #12011
Fixes #10250

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 requested a review from fisker January 1, 2022 18:13
@fisker
Copy link
Member

fisker commented Jan 2, 2022

Prettier pr-12017
Playground link

--parser babel

Input:

if (condition1) expression1; /**/ // comment A
else if (condition2) expression2; /**/ // comment B
else expression3; /**/ // comment C

Output:

if (condition1)
  expression1; /**/
  // comment A
else if (condition2)
  expression2; /**/
  // comment B
else expression3; /**/ // comment C

@sosukesuzuki
Copy link
Member Author

@fisker I don't think such code is written in real world so we can ignore it.

@sosukesuzuki
Copy link
Member Author

@fisker What do you think about this?

/**
* This is used as a marker for dangling comments.
*/
const markerForIfWithoutBlockAndSameLineComment =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Symbol here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sosukesuzuki sosukesuzuki merged commit a50bc4e into prettier:main Jan 6, 2022
@sosukesuzuki sosukesuzuki deleted the fix-12011 branch January 6, 2022 00:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve end of line comments on the same line why the if comment is line breaked?
2 participants