1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::pass::Pass;
use ast::*;
use swc_common::Fold;

struct OptionalCatchBinding;

pub fn optional_catch_binding() -> impl Pass {
    OptionalCatchBinding
}

impl Fold<CatchClause> for OptionalCatchBinding {
    fn fold(&mut self, cc: CatchClause) -> CatchClause {
        if cc.param.is_some() {
            return cc;
        }

        CatchClause {
            param: Some(private_ident!("e").into()),
            ..cc
        }
    }
}

#[cfg(test)]
mod tests {
    use super::optional_catch_binding as tr;

    test!(
        ::swc_ecma_parser::Syntax::default(),
        |_| tr(),
        issue_411,
        "try {} catch {}",
        "try {} catch(e) {}"
    );
}