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 comments print in IfStatement
#15076
Conversation
|
||
// TODO[@fisker]: fix this | ||
// if (a) var a = 1; /* comment 6e */ | ||
// else return 2; |
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.
markerForIfWithoutBlockAndSameLineComment
was introduced in #12017, do you remember why we attach the comment as dangling instead of trailing comment?
Many nodes can be a child of IfStatement
, though this code is not reasonable, but still valid, the comment is not printed.
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 forget... but I tried to run tests in local with:
- addDanglingComment(
- precedingNode,
- comment,
- markerForIfWithoutBlockAndSameLineComment,
- );
+ addTrailingComment(precedingNode, comment);
then I got the spanpshot diffs like this:
- if (a === 0) expr; // comment A3
- else if (a === 1) expr; // comment B3
+ if (a === 0)
+ expr; // comment A3
+ else if (a === 1)
+ expr; // comment B3
At the time, I may have wanted to avoid this line break.
@@ -93,26 +93,44 @@ parsers: ["babel", "flow", "typescript"] | |||
printWidth: 80 | |||
| printWidth | |||
=====================================input====================================== | |||
if (a === 0) doSomething(); // comment A1 | |||
if (a === 0) doSomething(); // comment A1 |
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.
Where does this extra spacing come from? Not sure if i is expected in output, but maybe I am missing something.
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 added to align IfStatement.conquest
.
Description
Fixes #15007
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨