Skip to content

Commit c9d4b51

Browse files
committed
fix(formatter): correct printing trailing comments for if statement with non-block consequent
1 parent f3b75c3 commit c9d4b51

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

crates/oxc_formatter/src/formatter/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'a> Comments<'a> {
189189
let comments = self.unprinted_comments();
190190
for (index, comment) in comments.iter().enumerate() {
191191
if self.source_text.all_bytes_match(pos, comment.span.start, |b| {
192-
matches!(b, b'\t' | b' ') || b.is_ascii_punctuation()
192+
matches!(b, b'\t' | b' ' | b'=' | b':')
193193
}) {
194194
if comment.is_line() || self.is_end_of_line_comment(comment) {
195195
return &comments[..=index];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (base.endsWith('.js') || base === `/worker-entries`); // for dev
2+
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
3+
if (base.endsWith('.js') || base === `/worker-entries`) a; // for dev
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
if (base.endsWith('.js') || base === `/worker-entries`); // for dev
6+
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
7+
if (base.endsWith('.js') || base === `/worker-entries`) a; // for dev
8+
9+
==================== Output ====================
10+
if (base.endsWith(".js") || base === `/worker-entries`); // for dev
11+
if (base.endsWith(".js") || base === `/worker-entries`) base = ""; // for dev
12+
if (base.endsWith(".js") || base === `/worker-entries`) a; // for dev
13+
14+
===================== End =====================

0 commit comments

Comments
 (0)