mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(formatter): Handle leading comment after array elision (#20987)
Fixes #20962
This commit is contained in:
1 parent
4216380bc0
commit
139ddd928b
3 files changed
+80
-7
No files matched your search
@@ -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),
|
||||
}
|
||||
}))
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
const foo = {
|
||||
createNewConnection: ([
|
||||
password,
|
||||
,
|
||||
// @ts-expect-error THIS SHOULD STAY HERE
|
||||
username,
|
||||
|
||||
]) => {
|
||||
void password; void username;
|
||||
},
|
||||
}
|
||||
@@ -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 =====================
|
||||
Reference in new issue
Block a user