diff --git a/crates/oxc_formatter/src/write/binary_like_expression.rs b/crates/oxc_formatter/src/write/binary_like_expression.rs index 950913d56a29e..bde744198b6fc 100644 --- a/crates/oxc_formatter/src/write/binary_like_expression.rs +++ b/crates/oxc_formatter/src/write/binary_like_expression.rs @@ -396,8 +396,13 @@ impl<'a> Format<'a> for BinaryLeftOrRightSide<'a, '_> { let operator_and_right_expression = format_with(|f| { write!(f, [space(), binary_like_expression.operator()])?; - if binary_like_expression.should_inline_logical_expression() { + let should_inline = binary_like_expression.should_inline_logical_expression(); + + if should_inline { write!(f, [space()])?; + if f.comments().has_leading_own_line_comment(right.span().start) { + return write!(f, soft_line_indent_or_space(right)); + } } else { write!(f, [soft_line_break_or_space()])?; } diff --git a/crates/oxc_formatter/src/write/intersection_type.rs b/crates/oxc_formatter/src/write/intersection_type.rs index bab3f6a1c4107..09889b07c9779 100644 --- a/crates/oxc_formatter/src/write/intersection_type.rs +++ b/crates/oxc_formatter/src/write/intersection_type.rs @@ -36,8 +36,10 @@ fn format_intersection_types<'a>( write!(f, item)?; } else { // If no object is involved, go to the next line if it breaks - if !is_prev_object_like && !is_object_like { - write!(f, [indent(&format_args!(soft_line_break_or_space(), item))])?; + 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))?; } else { write!(f, space())?; diff --git a/tasks/prettier_conformance/snapshots/prettier.js.snap.md b/tasks/prettier_conformance/snapshots/prettier.js.snap.md index 1ba22ebe03556..fd3b394e4e064 100644 --- a/tasks/prettier_conformance/snapshots/prettier.js.snap.md +++ b/tasks/prettier_conformance/snapshots/prettier.js.snap.md @@ -1,4 +1,4 @@ -js compatibility: 698/749 (93.19%) +js compatibility: 699/749 (93.32%) # Failed @@ -32,7 +32,6 @@ js compatibility: 698/749 (93.19%) | js/if/trailing_comment.js | 💥 | 91.43% | | js/label/empty_label.js | 💥 | 66.67% | | js/last-argument-expansion/dangling-comment-in-arrow-function.js | 💥 | 22.22% | -| js/logical-expressions/multiple-comments/17192.js | 💥 | 60.00% | | js/object-multiline/multiline.js | 💥✨ | 22.22% | | js/quote-props/classes.js | 💥💥✨✨ | 47.06% | | js/quote-props/objects.js | 💥💥✨✨ | 45.10% | diff --git a/tasks/prettier_conformance/snapshots/prettier.ts.snap.md b/tasks/prettier_conformance/snapshots/prettier.ts.snap.md index 51d7641b82c21..471de0efddf58 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: 545/598 (91.14%) +ts compatibility: 547/598 (91.47%) # Failed @@ -22,7 +22,6 @@ ts compatibility: 545/598 (91.14%) | typescript/class-comment/class-implements.ts | 💥 | 98.89% | | typescript/class-comment/declare.ts | 💥 | 84.62% | | typescript/class-comment/generic.ts | 💥 | 92.00% | -| typescript/comments/16121.ts | 💥 | 72.46% | | typescript/comments/mapped_types.ts | 💥 | 96.77% | | typescript/comments/method_types.ts | 💥 | 82.05% | | typescript/conditional-types/comments.ts | 💥✨ | 31.51% | @@ -40,7 +39,6 @@ ts compatibility: 545/598 (91.14%) | typescript/interface2/break/break.ts | 💥💥💥 | 82.30% | | typescript/intersection/intersection-parens.ts | 💥💥 | 86.17% | | typescript/intersection/consistent-with-flow/intersection-parens.ts | 💥 | 69.77% | -| typescript/intersection/mutiple-comments/17192.ts | 💥 | 60.00% | | 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% |