Skip to content
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
18 changes: 11 additions & 7 deletions crates/oxc_formatter/src/formatter/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> Printer<'a> {
}
};
let buffer = CodeBuffer::with_indent(indent_char, indent_width);
Self { options, state: PrinterState { buffer, ..Default::default() } }
Self { options, state: PrinterState::new(buffer) }
}

/// Prints the passed in element as well as all its content
Expand Down Expand Up @@ -456,8 +456,6 @@ impl<'a> Printer<'a> {

measurer.finish();

self.state.measured_group_fits = true;

// Print all pairs that fit in flat mode.
for _ in 0..flat_pairs {
self.print_fill_item(
Expand Down Expand Up @@ -655,10 +653,6 @@ impl<'a> Printer<'a> {
}

self.state.line_width = 0;

// Fit's only tests if groups up to the first line break fit.
// The next group must re-measure if it still fits.
self.state.measured_group_fits = false;
} else {
let char_width = if char == '\t' {
// SAFETY: `'\t'` is an valid ASCII character
Expand Down Expand Up @@ -714,6 +708,16 @@ struct PrinterState<'a> {
fits_queue: Vec<&'a [FormatElement<'a>]>,
}

impl PrinterState<'_> {
pub fn new(buffer: CodeBuffer) -> Self {
Self {
buffer,
// Initialize `measured_group_fits` to true to indicate that groups are initially assumed to fit.
measured_group_fits: true,
..Default::default()
}
}
}
/// Tracks the mode in which groups with ids are printed. Stores the groups at `group.id()` index.
/// This is based on the assumption that the group ids for a single document are dense.
#[derive(Debug, Default)]
Expand Down
12 changes: 12 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/jsx/issue-16199.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function ProTip() {
return (
<T>
<X />
Pro tip: See more{' '}
<Link href="https://mui.com/getting-started/templates/">
BREAK THIS
</Link>{' '}
on the MUI documentation.
</T>
)
}
49 changes: 49 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/jsx/issue-16199.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
export default function ProTip() {
return (
<T>
<X />
Pro tip: See more{' '}
<Link href="https://mui.com/getting-started/templates/">
BREAK THIS
</Link>{' '}
on the MUI documentation.
</T>
)
}
==================== Output ====================
------------------
{ printWidth: 80 }
------------------
export default function ProTip() {
return (
<T>
<X />
Pro tip: See more{" "}
<Link href="https://mui.com/getting-started/templates/">
BREAK THIS
</Link>{" "}
on the MUI documentation.
</T>
);
}

-------------------
{ printWidth: 100 }
-------------------
export default function ProTip() {
return (
<T>
<X />
Pro tip: See more <Link href="https://mui.com/getting-started/templates/">
BREAK THIS
</Link> on
the MUI documentation.
</T>
);
}

===================== End =====================
Loading