-
Notifications
You must be signed in to change notification settings - Fork 660
fix(rome_js_formatter): jsx punctuation #3842
Conversation
✅ Deploy Preview for docs-rometools canceled.Built without sensitive environment variables
|
// ,<div>Second</div> | ||
// </div> | ||
// ``` | ||
!next_word.is_next_element_self_closing() |
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 know the best solution how we can check two elements from current. =(
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 looks reasonable to me or you can either:
- Roll your own iterator that allows a lookahead of two tokens (storing current, and next, and the iterator)
- Not use
Peekable
and instead have three local variables:
let mut last = None;
let mut current = iter.next();
let mut next = iter.next();
let mut next_next = iter.next();
// And then at the end do
last = current;
current = next;
next = next_next;
next_next = iter.next()
This may be bad for performance tough because it requires writing a lot of data (OK, only one next more)
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.
https://github.com/rome/tools/pull/3842/files#diff-cf7a3c4832f78d40375de484c0abaeeceacc486aa2ca3bc4344ad4d33dce6b2aR512-R560
Implement JsxChildrenIterator
which allows a lookahead of two tokens
@@ -130,8 +130,46 @@ third = ( | |||
```diff | |||
--- Prettier | |||
+++ Rome | |||
@@ -80,15 +80,23 @@ | |||
|
|||
@@ -1,15 +1,12 @@ |
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.
Prettier treats fbt translation tag
https://github.com/prettier/prettier/blob/b0d9387b95cdd4e9d50f5999d3be53b0b5d03a97/src/language-js/print/jsx.js#L416-L418
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.
Yeah, that's something we don't want to
1c0e84d
to
50e2819
Compare
@@ -82,7 +81,8 @@ impl FormatJsxChildList { | |||
children.pop(); | |||
} | |||
|
|||
let mut children_iter = children.into_iter().peekable(); | |||
let mut last: Option<&JsxChild> = None; | |||
let mut children_iter = JsxChildrenIterator::new(children.iter()); |
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.
Nit: Use into_iter()
so that the elements get disposed while iterating and that next
returns owned values
Summary
Fix #3531 (comment)
Test Plan
cargo test -p rome_js_formatter