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
25 changes: 12 additions & 13 deletions crates/oxc_formatter/src/print/mapped_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSMappedType<'a>> {
let key = self.key();
let constraint = self.constraint();
let name_type = self.name_type();
let should_expand = has_line_break_before_property_name(self, f.source_text());
let should_expand = has_line_break_after_opening_brace(self, f.source_text());

let format_inner = format_with(|f| {
if should_expand {
Expand Down Expand Up @@ -84,16 +84,15 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSMappedType<'a>> {
}
}

/// Check if the user introduced a new line inside the node, but only if
/// that new line occurs at or before the property name. For example,
/// this would break:
/// { [
/// A in B]: T}
/// Because the line break occurs before `A`, the property name. But this
/// would _not_ break:
/// { [A
/// in B]: T}
/// Because the break is _after_ the `A`.
fn has_line_break_before_property_name(node: &TSMappedType, f: SourceText) -> bool {
f.contains_newline_between(node.span.start, node.key.span.start)
/// Check if the user introduced a new line immediately after the opening brace.
/// For example, this would break:
/// {
/// readonly [A in B]: T}
/// Because the line break occurs right after `{`. But this would _not_ break:
/// { readonly
/// [A in B]: T}
/// Because the break is not immediately after `{`.
fn has_line_break_after_opening_brace(node: &TSMappedType, f: SourceText) -> bool {
// Check if there's a newline immediately after `{` (before any non-whitespace)
f.has_newline_after(node.span.start + 1)
}
3 changes: 1 addition & 2 deletions tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ts compatibility: 584/605 (96.53%)
ts compatibility: 585/605 (96.69%)

# Failed

Expand All @@ -17,7 +17,6 @@ ts compatibility: 584/605 (96.53%)
| typescript/interface2/comments-ts-only/18278.ts | 💥 | 95.65% |
| typescript/last-argument-expansion/decorated-function.tsx | 💥 | 29.06% |
| typescript/mapped-type/issue-11098.ts | 💥 | 97.03% |
| typescript/mapped-type/break-mode/break-mode.ts | 💥 | 68.75% |
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |
| typescript/top-level-await/test.ts | 💥 | 0.00% |
| typescript/top-level-await/test.tsx | 💥 | 0.00% |
Expand Down
Loading