swc_ecma_transforms_optimization/simplify/
mod.rs

1//! Ported from closure compiler.
2use swc_common::{
3    pass::{CompilerPass, Repeat, Repeated},
4    Mark,
5};
6use swc_ecma_ast::Pass;
7
8pub use self::{
9    branch::dead_branch_remover,
10    expr::{expr_simplifier, Config as ExprSimplifierConfig},
11};
12
13mod branch;
14pub mod const_propagation;
15pub mod dce;
16pub mod expr;
17pub mod inlining;
18
19#[derive(Debug, Default)]
20pub struct Config {
21    pub dce: dce::Config,
22    pub inlining: inlining::Config,
23    pub expr: ExprSimplifierConfig,
24}
25
26/// Performs simplify-expr, inlining, remove-dead-branch and dce until nothing
27/// changes.
28pub fn simplifier(unresolved_mark: Mark, c: Config) -> impl CompilerPass + Pass + Repeated {
29    Repeat::new((
30        expr_simplifier(unresolved_mark, c.expr),
31        dead_branch_remover(unresolved_mark),
32        dce::dce(c.dce, unresolved_mark),
33    ))
34}