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
13 changes: 8 additions & 5 deletions crates/oxc_formatter/src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,17 @@ impl<'a> FormatWrite<'a> for AstNode<'a, IfStatement<'a>> {
}

if has_dangling_comments {
write!(
f,
FormatDanglingComments::Comments { comments, indent: DanglingIndentMode::None }
)?;

if has_line_comment {
write!(f, FormatTrailingComments::Comments(comments))?;
write!(f, hard_line_break())?;
} else {
write!(
f,
FormatDanglingComments::Comments {
comments,
indent: DanglingIndentMode::None
}
)?;
write!(f, space())?;
}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_formatter/tests/fixtures/ts/comments/if.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if (true) {}

// comment1
else if (false) {}

// comment2

else {}
25 changes: 25 additions & 0 deletions crates/oxc_formatter/tests/fixtures/ts/comments/if.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
if (true) {}

// comment1
else if (false) {}

// comment2

else {}
==================== Output ====================
if (true) {
}

// comment1
else if (false) {
}

// comment2
else {
}

===================== End =====================
Loading