Skip to content

Commit 9b5bba5

Browse files
committed
[core][rewriter] destructure_rewrites: clean try catch statements
1 parent 704a541 commit 9b5bba5

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

rewriter/js/src/visitor.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ where
247247
restids: &mut Vec<Atom<'data>>,
248248
location_assigned: &mut bool,
249249
) {
250-
dbg!(it);
251250
match &it.kind {
252251
BindingPatternKind::BindingIdentifier(p) => {
253252
// let a = 0;
@@ -445,7 +444,7 @@ where
445444
// do not walk further, we don't want to rewrite the identifiers
446445
}
447446

448-
#[cfg(feature = "debug")]
447+
// #[cfg(feature = "debug")]
449448
fn visit_try_statement(&mut self, it: &oxc::ast::ast::TryStatement<'data>) {
450449
// for debugging we need to know what the error was
451450

@@ -459,7 +458,28 @@ where
459458
.add(rewrite!(Span::new(start, start), ScramErr { ident }));
460459
}
461460

462-
walk::walk_try_statement(self, it);
461+
if !self.flags.destructure_rewrites {
462+
walk::walk_try_statement(self, it);
463+
return;
464+
}
465+
466+
dbg!(&it);
467+
if let Some(h) = &it.handler {
468+
if let Some(p) = &h.param {
469+
let mut restids: Vec<Atom<'data>> = Vec::new();
470+
let mut location_assigned: bool = false;
471+
472+
self.recurse_binding_pattern(&p.pattern, &mut restids, &mut location_assigned);
473+
self.jschanges.add(rewrite!(
474+
h.body.body[0].span(),
475+
CleanFunction {
476+
restids,
477+
expression: false,
478+
}
479+
));
480+
}
481+
}
482+
463483
}
464484

465485
fn visit_object_expression(&mut self, it: &ObjectExpression<'data>) {

0 commit comments

Comments
 (0)