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
28 changes: 21 additions & 7 deletions crates/oxc_formatter/src/ast_nodes/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ macro_rules! impl_ast_node_vec_for_option {
parent: self.parent,
allocator: self.allocator,
following_span_start: inner_iter
.next()
.and_then(|opt| opt.as_ref().map(|n| n.span().start))
// Skip over `None` (elision) to find the next real element's span
.find_map(|opt| opt.as_ref().map(|n| n.span().start))
.unwrap_or(following),
}
}))
Expand Down Expand Up @@ -228,11 +228,25 @@ macro_rules! impl_ast_node_vec_for_option {
let following = self.following_span_start;
let get_span = self.get_following_span_start;
allocator
.alloc(self.inner.next().map(|inner| AstNode {
parent: self.parent,
inner,
allocator,
following_span_start: self.inner.peek().map_or(following, |n| get_span(*n)),
.alloc(self.inner.next().map(|inner| {
AstNode {
parent: self.parent,
inner,
allocator,
following_span_start: match self.inner.peek().map(|n| get_span(n)) {
Some(span) if span != 0 => span,
// Skip over `None` (elision) to find the next real element's span
Some(_) => self
.inner
.clone()
.find_map(|n| {
let span = get_span(n);
(span != 0).then_some(span)
})
.unwrap_or(following),
None => following,
},
}
}))
.as_ref()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const foo = {
createNewConnection: ([
password,
,
// @ts-expect-error THIS SHOULD STAY HERE
username,

]) => {
void password; void username;
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
const foo = {
createNewConnection: ([
password,
,
// @ts-expect-error THIS SHOULD STAY HERE
username,

]) => {
void password; void username;
},
}

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
const foo = {
createNewConnection: ([
password,
,
// @ts-expect-error THIS SHOULD STAY HERE
username,
]) => {
void password;
void username;
},
};

-------------------
{ printWidth: 100 }
-------------------
const foo = {
createNewConnection: ([
password,
,
// @ts-expect-error THIS SHOULD STAY HERE
username,
]) => {
void password;
void username;
},
};

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