diff --git a/crates/oxc_formatter/src/formatter/format_element/mod.rs b/crates/oxc_formatter/src/formatter/format_element/mod.rs index 34937e8235903..dddb96e3efa03 100644 --- a/crates/oxc_formatter/src/formatter/format_element/mod.rs +++ b/crates/oxc_formatter/src/formatter/format_element/mod.rs @@ -393,7 +393,6 @@ pub trait FormatElements { /// Returns the end tag if: /// * the last element is an end tag of `kind` - #[expect(unused)] fn end_tag(&self, kind: TagKind) -> Option<&Tag>; } diff --git a/crates/oxc_formatter/src/write/jsx/child_list.rs b/crates/oxc_formatter/src/write/jsx/child_list.rs index 83138216b8db2..3a480c6c13755 100644 --- a/crates/oxc_formatter/src/write/jsx/child_list.rs +++ b/crates/oxc_formatter/src/write/jsx/child_list.rs @@ -122,7 +122,7 @@ impl FormatJsxChildList { let is_trailing_or_only_whitespace = children_iter.peek().is_none(); if is_trailing_or_only_whitespace || is_after_line_break { - multiline.write_separator(&JsxRawSpace, f); + multiline.write_separator_in_last_entry(&JsxRawSpace, f); } // Leading whitespace. Only possible if used together with a expression child // @@ -599,6 +599,20 @@ impl<'a> MultilineBuilder<'a> { }; } + /// Writes a separator into the last entry if it is an entry. + fn write_separator_in_last_entry( + &mut self, + separator: &dyn Format<'a>, + f: &mut Formatter<'_, 'a>, + ) { + if self.result.last().is_some_and(|element| element.end_tag(TagKind::Entry).is_some()) { + let last_index = self.result.len() - 1; + self.result.insert(last_index, f.intern(separator).unwrap()); + } else { + self.write_content(separator, f); + } + } + fn finish(self) -> FormatMultilineChildren<'a> { FormatMultilineChildren { layout: self.layout, elements: RefCell::new(self.result) } } diff --git a/tasks/prettier_conformance/snapshots/prettier.js.snap.md b/tasks/prettier_conformance/snapshots/prettier.js.snap.md index 9e94ac7936455..0dccc37ad858f 100644 --- a/tasks/prettier_conformance/snapshots/prettier.js.snap.md +++ b/tasks/prettier_conformance/snapshots/prettier.js.snap.md @@ -1,4 +1,4 @@ -js compatibility: 734/759 (96.71%) +js compatibility: 735/759 (96.84%) # Failed @@ -28,4 +28,3 @@ js compatibility: 734/759 (96.71%) | jsx/fbt/test.js | 💥 | 84.06% | | jsx/ignore/spread.js | 💥 | 83.33% | | jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% | -| jsx/text-wrap/test.js | 💥 | 99.56% | diff --git a/tasks/prettier_conformance/snapshots/prettier.ts.snap.md b/tasks/prettier_conformance/snapshots/prettier.ts.snap.md index e2beda2aac416..1ab91b2483ddd 100644 --- a/tasks/prettier_conformance/snapshots/prettier.ts.snap.md +++ b/tasks/prettier_conformance/snapshots/prettier.ts.snap.md @@ -1,4 +1,4 @@ -ts compatibility: 573/604 (94.87%) +ts compatibility: 574/604 (95.03%) # Failed @@ -7,7 +7,6 @@ ts compatibility: 573/604 (94.87%) | jsx/fbt/test.js | 💥 | 84.06% | | jsx/ignore/spread.js | 💥 | 83.33% | | jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% | -| jsx/text-wrap/test.js | 💥 | 99.56% | | typescript/arrow/comments.ts | 💥✨ | 44.44% | | typescript/arrow/comments/issue-11100.ts | 💥 | 84.00% | | typescript/as/as-const/as-const.ts | 💥 | 90.91% |