Skip to content
Closed
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
27 changes: 15 additions & 12 deletions crates/oxc_formatter/src/formatter/format_element/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ impl Document<'_> {
_ => false,
},
FormatElement::Interned(interned) => {
if let Some(interned_expands) = checked_interned.get(interned) {
*interned_expands
} else {
let interned_expands =
propagate_expands(interned, enclosing, checked_interned);
checked_interned.insert(interned, interned_expands);
interned_expands
}
// if let Some(interned_expands) = checked_interned.get(interned) {
// *interned_expands
// } else {
let interned_expands =
propagate_expands(interned, enclosing, checked_interned);
checked_interned.insert(interned, interned_expands);
interned_expands
// }
}
FormatElement::BestFitting(best_fitting) => {
enclosing.push(Enclosing::BestFitting);

for variant in best_fitting.variants() {
propagate_expands(variant, enclosing, checked_interned);
let mut expanded = true;
for variant in best_fitting.non_expanded_variants() {
let res = propagate_expands(variant, enclosing, checked_interned);
if expanded {
expanded = res;
}
}

enclosing.pop();
Expand Down Expand Up @@ -110,7 +113,7 @@ impl Document<'_> {
// Instead, just returning false here enforces that `best_fitting` doesn't
// think it expands _itself_, but allows other sibling elements to still
// propagate their expansion.
false
expanded
}
// `FormatElement::Token` cannot contain line breaks
FormatElement::Text { text: _, width } => width.is_multiline(),
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_formatter/src/formatter/format_element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ impl<'a> BestFittingElement<'a> {
self.variants
}

pub fn non_expanded_variants(&self) -> &[&'a [FormatElement<'a>]] {
&self.variants[..self.variants.len() - 1]
}

/// Returns the least expanded variant
pub fn most_flat(&self) -> &[FormatElement<'a>] {
self.variants.first().expect(
Expand Down
Loading