mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): format empty try catch (#1430)
This commit is contained in:
parent
18fa8e45a4
commit
cf388ae79e
4 changed files with 20 additions and 12 deletions
|
|
@ -25,7 +25,9 @@ pub(super) fn print_block<'a>(
|
|||
| AstKind::ForStatement(_)
|
||||
| AstKind::WhileStatement(_)
|
||||
| AstKind::DoWhileStatement(_)
|
||||
) || matches!(p.current_kind(), AstKind::StaticBlock(_)))
|
||||
) || (matches!(parent, AstKind::CatchClause(_))
|
||||
&& !matches!(p.parent_parent_kind(), Some(AstKind::TryStatement(stmt)) if stmt.finalizer.is_some()))
|
||||
|| matches!(p.current_kind(), AstKind::StaticBlock(_)))
|
||||
{
|
||||
parts.push(hardline!());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -474,17 +474,19 @@ impl<'a> Format<'a> for TryStatement<'a> {
|
|||
|
||||
impl<'a> Format<'a> for CatchClause<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
let mut parts = p.vec();
|
||||
wrap!(p, self, CatchClause, {
|
||||
let mut parts = p.vec();
|
||||
|
||||
parts.push(ss!("catch "));
|
||||
if let Some(param) = &self.param {
|
||||
parts.push(ss!("("));
|
||||
parts.push(format!(p, param));
|
||||
parts.push(ss!(") "));
|
||||
}
|
||||
parts.push(format!(p, self.body));
|
||||
parts.push(ss!("catch "));
|
||||
if let Some(param) = &self.param {
|
||||
parts.push(ss!("("));
|
||||
parts.push(format!(p, param));
|
||||
parts.push(ss!(") "));
|
||||
}
|
||||
parts.push(format!(p, self.body));
|
||||
|
||||
Doc::Array(parts)
|
||||
Doc::Array(parts)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ impl<'a> Prettier<'a> {
|
|||
self.nodes[self.nodes.len() - 2]
|
||||
}
|
||||
|
||||
fn parent_parent_kind(&self) -> Option<AstKind<'a>> {
|
||||
let len = self.nodes.len();
|
||||
(len >= 3).then(|| self.nodes[len - 3])
|
||||
}
|
||||
|
||||
/// A hack for erasing the lifetime requirement.
|
||||
#[allow(clippy::unused_self)]
|
||||
fn alloc<T>(&self, t: &T) -> &'a T {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Compatibility: 121/838 (14.44%)
|
||||
Compatibility: 122/838 (14.56%)
|
||||
|
||||
# Failed
|
||||
|
||||
|
|
@ -954,7 +954,6 @@ Compatibility: 121/838 (14.44%)
|
|||
|
||||
### try
|
||||
* try/catch.js
|
||||
* try/empty.js
|
||||
* try/try.js
|
||||
|
||||
### tuple
|
||||
|
|
|
|||
Loading…
Reference in a new issue