-
Notifications
You must be signed in to change notification settings - Fork 659
fix(rome_js_formatter): comments in closing JSX elements #4244
Conversation
✅ Deploy Preview for docs-rometools canceled.Built without sensitive environment variables
|
cc @MichaReiser that worked on source maps and comments |
I recommend reading prettier's source code to understand their formatting (and how it may have changed) |
I already have an idea for addressing the issue. My current problem is with the Rome code base. I cannot understand why my piece of code fails. In the following code, <a></ /* comment */a> I think so that it was also a dangling comment of the entire JsxClosingElement |
Our JavaScript formatter also uses an extensive list of custom-rules to place comments (same as prettier). The way I like to approach comments related issues is to log the comments inside the test. let syntax = SourceType::jsx();
let tree = parse("<a></ /* block1 */ // test\na>;", syntax);
let formatted = format_node(JsFormatOptions::new(syntax), &tree.syntax()).unwrap();
dbg!(&formatted.context().comments()); That helps me understand if the comments are associated with the correct nodes. You may want to compare the output with Prettier using their playground. |
@MichaReiser
In the rome playground, EDIT: I see: it is a trailing comment of |
The fix is not ideal. However, this removes one of the issues that block the update of prettier snapshots. |
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.
How does this approach compare to prettier's handling? What do you consider non-ideal with this solution?
In prettier the following code: <a></ /* block1 */ // test
a>; is formatted to: <a></
/* block1 */ // test
a
>; While the current fix outputs: <a></
/* block1 */ // test
a
>; EDIT: it is now fixed :) |
@MichaReiser I managed to match prettier output :) It was harder than I thought to understand the formatter logic. |
Amazing work @Conaclos !!!
Yeah dealing with the formatter is not a easy task! |
Summary
This is a tentative to fix #4243.
This is blocking the update of prettier snapshots #4234.
I copied the code from
closing_fragment.rs
because the formatting is correct for fragments:is correctly formatted to:
Unfortunately this has no effect:
still produces the following error:
Test Plan
Test included
Documentation
No change