Skip to content

Commit 643202d

Browse files
committed
fix(formatter): multiple comments in LogicalExpression and IntersectionType
1 parent 03f0970 commit 643202d

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

crates/oxc_formatter/src/write/binary_like_expression.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,13 @@ impl<'a> Format<'a> for BinaryLeftOrRightSide<'a, '_> {
396396
let operator_and_right_expression = format_with(|f| {
397397
write!(f, [space(), binary_like_expression.operator()])?;
398398

399-
if binary_like_expression.should_inline_logical_expression() {
399+
let should_inline = binary_like_expression.should_inline_logical_expression();
400+
401+
if should_inline {
400402
write!(f, [space()])?;
403+
if f.comments().has_leading_own_line_comment(right.span().start) {
404+
return write!(f, soft_line_indent_or_space(right));
405+
}
401406
} else {
402407
write!(f, [soft_line_break_or_space()])?;
403408
}

crates/oxc_formatter/src/write/intersection_type.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ fn format_intersection_types<'a>(
3636
write!(f, item)?;
3737
} else {
3838
// If no object is involved, go to the next line if it breaks
39-
if !is_prev_object_like && !is_object_like {
40-
write!(f, [indent(&format_args!(soft_line_break_or_space(), item))])?;
39+
if !(is_prev_object_like || is_object_like)
40+
|| f.comments().has_leading_own_line_comment(item.span().start)
41+
{
42+
write!(f, soft_line_indent_or_space(item))?;
4143
} else {
4244
write!(f, space())?;
4345

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 698/749 (93.19%)
1+
js compatibility: 699/749 (93.32%)
22

33
# Failed
44

@@ -32,7 +32,6 @@ js compatibility: 698/749 (93.19%)
3232
| js/if/trailing_comment.js | 💥 | 91.43% |
3333
| js/label/empty_label.js | 💥 | 66.67% |
3434
| js/last-argument-expansion/dangling-comment-in-arrow-function.js | 💥 | 22.22% |
35-
| js/logical-expressions/multiple-comments/17192.js | 💥 | 60.00% |
3635
| js/object-multiline/multiline.js | 💥✨ | 22.22% |
3736
| js/quote-props/classes.js | 💥💥✨✨ | 47.06% |
3837
| js/quote-props/objects.js | 💥💥✨✨ | 45.10% |

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 545/598 (91.14%)
1+
ts compatibility: 547/598 (91.47%)
22

33
# Failed
44

@@ -22,7 +22,6 @@ ts compatibility: 545/598 (91.14%)
2222
| typescript/class-comment/class-implements.ts | 💥 | 98.89% |
2323
| typescript/class-comment/declare.ts | 💥 | 84.62% |
2424
| typescript/class-comment/generic.ts | 💥 | 92.00% |
25-
| typescript/comments/16121.ts | 💥 | 72.46% |
2625
| typescript/comments/mapped_types.ts | 💥 | 96.77% |
2726
| typescript/comments/method_types.ts | 💥 | 82.05% |
2827
| typescript/conditional-types/comments.ts | 💥✨ | 31.51% |
@@ -40,7 +39,6 @@ ts compatibility: 545/598 (91.14%)
4039
| typescript/interface2/break/break.ts | 💥💥💥 | 82.30% |
4140
| typescript/intersection/intersection-parens.ts | 💥💥 | 86.17% |
4241
| typescript/intersection/consistent-with-flow/intersection-parens.ts | 💥 | 69.77% |
43-
| typescript/intersection/mutiple-comments/17192.ts | 💥 | 60.00% |
4442
| typescript/last-argument-expansion/decorated-function.tsx | 💥 | 29.06% |
4543
| typescript/mapped-type/issue-11098.ts | 💥 | 97.03% |
4644
| typescript/mapped-type/break-mode/break-mode.ts | 💥 | 68.75% |

0 commit comments

Comments
 (0)