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
10 changes: 9 additions & 1 deletion crates/oxc_formatter/src/write/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ impl<'a> Format<'a> for AstNode<'a, Vec<'a, Directive<'a>>> {
//```
// so we should keep an extra empty line after JsDirectiveList

let need_extra_empty_line = f.source_text().lines_after(last_directive.span.end) > 1;
let end = if let Some(last_printed_comment) = f.comments().printed_comments().last()
&& last_printed_comment.span.end > last_directive.span.end
{
last_printed_comment.span.end
} else {
last_directive.span.end
};

let need_extra_empty_line = f.source_text().lines_after(end) > 1;
write!(f, if need_extra_empty_line { empty_line() } else { hard_line_break() })
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

// comment
(() => {});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
"use strict";

// comment
(() => {});
==================== Output ====================
"use strict";

// comment
() => {};

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