swc_ecma_minifier/compress/pure/
unsafes.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use swc_ecma_ast::*;
use swc_ecma_utils::ExprExt;

use super::Pure;

impl Pure<'_> {
    /// Drop arguments of `Symbol()` call.
    pub(super) fn drop_arguments_of_symbol_call(&mut self, e: &mut CallExpr) {
        if !self.options.unsafe_symbols {
            return;
        }

        match &e.callee {
            Callee::Super(_) | Callee::Import(_) => return,
            Callee::Expr(callee) => match &**callee {
                Expr::Ident(Ident { sym, .. }) if &**sym == "Symbol" => {}
                _ => return,
            },
        }

        e.args
            .retain(|arg| arg.expr.may_have_side_effects(&self.expr_ctx));
    }
}