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
//! Ported from closure compiler.
use swc_common::{chain, pass::Repeat, Mark};
use swc_ecma_transforms_base::pass::RepeatedJsPass;

pub use self::{
    branch::dead_branch_remover,
    expr::{expr_simplifier, Config as ExprSimplifierConfig},
};

mod branch;
pub mod const_propagation;
pub mod dce;
mod expr;
pub mod inlining;

#[derive(Debug, Default)]
pub struct Config {
    pub dce: dce::Config,
    pub inlining: inlining::Config,
    pub expr: ExprSimplifierConfig,
}

/// Performs simplify-expr, inlining, remove-dead-branch and dce until nothing
/// changes.
pub fn simplifier(unresolved_mark: Mark, c: Config) -> impl RepeatedJsPass {
    Repeat::new(chain!(
        expr_simplifier(unresolved_mark, c.expr),
        dead_branch_remover(unresolved_mark),
        dce::dce(c.dce, unresolved_mark)
    ))
}