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: 10 additions & 0 deletions crates/oxc_formatter/src/formatter/separated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use oxc_span::{GetSpan, Span};

use crate::{
Expand All @@ -21,6 +23,14 @@ pub struct FormatSeparatedElement<E: GetSpan> {
options: FormatSeparatedOptions,
}

impl<T: GetSpan> Deref for FormatSeparatedElement<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.element
}
}

impl<T: GetSpan> GetSpan for FormatSeparatedElement<T> {
fn span(&self) -> Span {
self.element.span()
Expand Down
9 changes: 8 additions & 1 deletion crates/oxc_formatter/src/write/variable_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ impl<'a> Format<'a> for AstNode<'a, Vec<'a, VariableDeclarator<'a>>> {
let first_declarator = declarators.next().unwrap();

if length == 1 && !f.comments().has_comment_before(first_declarator.span().start) {
return write!(f, first_declarator);
return if first_declarator.init.is_none()
&& f.comments()
.has_comment_in_range(first_declarator.span.end, self.parent.span().end)
{
write!(f, indent(&first_declarator));
} else {
write!(f, &first_declarator);
};
}

write!(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const PAGE_PATH: string
//<- THIS spaces
;(()=>{})()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
declare const PAGE_PATH: string
//<- THIS spaces
;(()=>{})()

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
declare const PAGE_PATH: string;
//<- THIS spaces
(() => {})();

-------------------
{ printWidth: 100 }
-------------------
declare const PAGE_PATH: string;
//<- THIS spaces
(() => {})();

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