Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_formatter): Printer fill fits #3307

Merged
merged 2 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/rome_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ impl<'a> Printer<'a> {
// variant.

// Try to fit only the first variant on a single line

if !matches!(variant.first(), Some(&FormatElement::Tag(Tag::StartEntry))) {
return invalid_start_tag(TagKind::Entry, variant.first());
}
Expand Down Expand Up @@ -438,6 +437,8 @@ impl<'a> Printer<'a> {
let mut current_fits =
self.fits_fill_entry(SingleEntryPredicate::default(), queue, stack)?;

self.state.measured_group_fits = current_fits;

self.print_entry(
queue,
stack,
Expand All @@ -458,6 +459,8 @@ impl<'a> Printer<'a> {
false
};

self.state.measured_group_fits = all_fits;

let separator_mode = if all_fits {
PrintMode::Flat
} else {
Expand All @@ -480,6 +483,8 @@ impl<'a> Printer<'a> {
let next_fits =
self.fits_fill_entry(SingleEntryPredicate::default(), queue, stack)?;

self.state.measured_group_fits = next_fits;

self.print_entry(
queue,
stack,
Expand Down
6 changes: 3 additions & 3 deletions crates/rome_js_formatter/src/jsx/tag/closing_element.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use rome_formatter::{format_args, write};
use rome_formatter::write;
use rome_js_syntax::{JsxClosingElement, JsxClosingElementFields};

#[derive(Debug, Clone, Default)]
Expand All @@ -21,13 +21,13 @@ impl FormatNodeRule<JsxClosingElement> for FormatJsxClosingElement {

write![
formatter,
[group(&format_args![
[
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These two changes aren't related to the bug but align our IR with Prettiers and made it easier to debug the issue

l_angle_token.format(),
slash_token.format(),
name.format(),
line_suffix_boundary(),
r_angle_token.format(),
])]
]
]
}
}
4 changes: 2 additions & 2 deletions crates/rome_js_formatter/src/jsx/tag/opening_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Format<JsFormatContext> for JsxAnyOpeningElement {
line_suffix_boundary(),
space(),
attributes.format(),
line_suffix_boundary(),
(!attributes.is_empty()).then_some(line_suffix_boundary()),
attribute_spacing,
format_close
]
Expand All @@ -82,7 +82,7 @@ impl Format<JsFormatContext> for JsxAnyOpeningElement {
type_arguments.format(),
line_suffix_boundary(),
soft_line_indent_or_space(&attributes.format()),
line_suffix_boundary(),
(!attributes.is_empty()).then_some(line_suffix_boundary()),
]
)?;

Expand Down