Skip to content

Commit c11cc07

Browse files
committed
fix(formatter): improve formatting for default type on type parameters (#15893)
Follow-up prettier/prettier#18041
1 parent 6ab1a20 commit c11cc07

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

crates/oxc_formatter/src/write/type_parameters.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
ast_nodes::{AstNode, AstNodes},
88
format_args,
99
formatter::{
10-
Buffer, Format, FormatError, FormatResult, Formatter, GroupId,
10+
Buffer, Format, FormatError, FormatResult, Formatter, GroupId, group_id,
1111
prelude::*,
1212
separated::FormatSeparatedIter,
1313
trivia::{DanglingIndentMode, FormatDanglingComments},
@@ -53,7 +53,17 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSTypeParameter<'a>> {
5353
)?;
5454
}
5555
if let Some(default) = &self.default() {
56-
write!(f, [space(), "=", space(), default])?;
56+
let group_id = f.group_id("default");
57+
write!(
58+
f,
59+
[
60+
space(),
61+
"=",
62+
group(&indent(&soft_line_break_or_space())).with_group_id(Some(group_id)),
63+
line_suffix_boundary(),
64+
indent_if_group_breaks(&default, group_id)
65+
]
66+
)?;
5767
}
5868
Ok(())
5969
}

tasks/prettier_conformance/snapshots/prettier.ts.snap.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 559/601 (93.01%)
1+
ts compatibility: 562/601 (93.51%)
22

33
# Failed
44

@@ -38,9 +38,6 @@ ts compatibility: 559/601 (93.01%)
3838
| typescript/non-null/optional-chain.ts | 💥 | 72.22% |
3939
| typescript/object-multiline/multiline.ts | 💥✨ | 23.21% |
4040
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |
41-
| typescript/type-params/18041.ts | 💥 | 43.75% |
42-
| typescript/type-params/constraints-and-default-2.ts | 💥 | 97.60% |
43-
| typescript/type-params/constraints-and-default.ts | 💥 | 87.32% |
4441
| typescript/union/inlining.ts | 💥 | 97.78% |
4542
| typescript/union/union-parens.ts | 💥 | 92.59% |
4643
| typescript/union/comments/18106.ts | 💥 | 90.48% |

0 commit comments

Comments
 (0)