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
2 changes: 0 additions & 2 deletions apps/oxfmt/conformance/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const categories: Category[] = [
"js-in-html(`<script>`)-in-js needs lot more work; Please see oxc_formatter/src/print/template/embed/html.rs",
"webawesome/relative-time/relative-time.test.ts":
"html-in-js: Need to solve `label({ embed, hug }))` + `shouldExpandLastArg`",
"webawesome/slider/slider.ts":
"`@decorator` + union type: https://github.com/oxc-project/oxc/issues/20519",
},
},
{
Expand Down
11 changes: 11 additions & 0 deletions crates/oxc_formatter/src/formatter/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,17 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
// is what the mode's initialized to by default
// This means, the printer is outside of the current element at this point and any
// line break should be printed as regular line break -> Fits
//
// Before returning, resolve any pending space so the width check is accurate.
// Without this, a deferred `Space` before a group boundary can be lost when
// the fits measurer exits early via an expanded-mode line break, causing the
// measured width to be off by one.
if self.state.pending_space {
self.state.line_width += 1;
if self.state.line_width > usize::from(self.options().print_width) {
return Ok(Fits::No);
}
}
return Ok(Fits::Yes);
}
}
Expand Down
23 changes: 23 additions & 0 deletions crates/oxc_formatter/tests/fixtures/ts/class/issue-20519.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Long decorator + union type: decorator should go on its own line
class SlSlider extends ShoelaceElement {
@property({ attribute: 'tooltip-placement', reflect: true }) tooltipPlacement: 'top' | 'right' |
'bottom' | 'left' =
'top';
}

// Short decorator + long union type: decorator should stay inline
class WaTooltip extends WebAwesomeElement {
@property() placement:
| "top"
| "top-start"
| "top-end"
| "right"
| "right-start"
| "right-end"
| "bottom"
| "bottom-start"
| "bottom-end"
| "left"
| "left-start"
| "left-end" = "bottom";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
assertion_line: 234
---
==================== Input ====================
// Long decorator + union type: decorator should go on its own line
class SlSlider extends ShoelaceElement {
@property({ attribute: 'tooltip-placement', reflect: true }) tooltipPlacement: 'top' | 'right' |
'bottom' | 'left' =
'top';
}

// Short decorator + long union type: decorator should stay inline
class WaTooltip extends WebAwesomeElement {
@property() placement:
| "top"
| "top-start"
| "top-end"
| "right"
| "right-start"
| "right-end"
| "bottom"
| "bottom-start"
| "bottom-end"
| "left"
| "left-start"
| "left-end" = "bottom";
}

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
// Long decorator + union type: decorator should go on its own line
class SlSlider extends ShoelaceElement {
@property({ attribute: "tooltip-placement", reflect: true })
tooltipPlacement: "top" | "right" | "bottom" | "left" = "top";
}

// Short decorator + long union type: decorator should stay inline
class WaTooltip extends WebAwesomeElement {
@property() placement:
| "top"
| "top-start"
| "top-end"
| "right"
| "right-start"
| "right-end"
| "bottom"
| "bottom-start"
| "bottom-end"
| "left"
| "left-start"
| "left-end" = "bottom";
}

-------------------
{ printWidth: 100 }
-------------------
// Long decorator + union type: decorator should go on its own line
class SlSlider extends ShoelaceElement {
@property({ attribute: "tooltip-placement", reflect: true }) tooltipPlacement:
| "top"
| "right"
| "bottom"
| "left" = "top";
}

// Short decorator + long union type: decorator should stay inline
class WaTooltip extends WebAwesomeElement {
@property() placement:
| "top"
| "top-start"
| "top-end"
| "right"
| "right-start"
| "right-end"
| "bottom"
| "bottom-start"
| "bottom-end"
| "left"
| "left-start"
| "left-end" = "bottom";
}

===================== End =====================
2 changes: 1 addition & 1 deletion tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ ts compatibility: 591/601 (98.34%)
| :-------- | :--------------: | :---------: |
| typescript/arrow/comments.ts | 💥✨ | 44.44% |
| typescript/arrow/comments/issue-11100.ts | 💥 | 84.00% |
| typescript/as/break-after-keyword/18148.ts | 💥 | 82.22% |
| typescript/class/empty-method-body.ts | 💥 | 80.00% |
| typescript/comments/mapped_types.ts | 💥 | 96.77% |
| typescript/comments/method_types.ts | 💥 | 82.05% |
| typescript/mapped-type/issue-11098.ts | 💥 | 97.03% |
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |
| typescript/union/comments/18389.ts | 💥 | 51.28% |
| typescript/union/consistent-with-flow/comment.ts | 💥 | 86.96% |
| typescript/union/single-type/single-type.ts | 💥 | 66.67% |
Loading