diff --git a/crates/oxc_formatter/src/print/intersection_type.rs b/crates/oxc_formatter/src/print/intersection_type.rs index 8cf27f12fcffc..0cf832abd3f29 100644 --- a/crates/oxc_formatter/src/print/intersection_type.rs +++ b/crates/oxc_formatter/src/print/intersection_type.rs @@ -5,6 +5,7 @@ use oxc_span::GetSpan; use crate::{ ast_nodes::AstNode, formatter::{Formatter, prelude::*}, + parentheses::NeedsParentheses, print::FormatWrite, utils::typescript::is_object_like_type, write, @@ -37,7 +38,13 @@ fn format_intersection_types<'a>( if !(is_prev_object_like || is_object_like) || f.comments().has_leading_own_line_comment(item.span().start) { - write!(f, soft_line_indent_or_space(item)); + let content = format_with(|f| { + if item.needs_parentheses(f) { + write!(f, format_leading_comments(item.span())); + } + write!(f, item); + }); + write!(f, soft_line_indent_or_space(&content)); } else { write!(f, space()); diff --git a/tasks/prettier_conformance/snapshots/prettier.ts.snap.md b/tasks/prettier_conformance/snapshots/prettier.ts.snap.md index 30411ed597681..c84c324798f71 100644 --- a/tasks/prettier_conformance/snapshots/prettier.ts.snap.md +++ b/tasks/prettier_conformance/snapshots/prettier.ts.snap.md @@ -1,4 +1,4 @@ -ts compatibility: 587/601 (97.67%) +ts compatibility: 588/601 (97.84%) # Failed @@ -15,6 +15,5 @@ ts compatibility: 587/601 (97.67%) | typescript/mapped-type/issue-11098.ts | 💥 | 97.03% | | typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% | | typescript/union/comments/18106.ts | 💥 | 92.68% | -| typescript/union/comments/18379.ts | 💥 | 87.27% | | typescript/union/comments/18389.ts | 💥 | 51.28% | | typescript/union/single-type/single-type.ts | 💥 | 66.67% |