Repository: swc-project/swc
File: crates/swc_ecma_minifier/src/compress/optimize/iife.rs (Rust)

Code before:

            _ => false,
        }
    }

    fn can_extract_param<'a>(
        &self,
        param_ids: impl ExactSizeIterator<Item = &'a Ident> + Clone,
        args: &[ExprOrSpread],
    ) -> bool {
        // Don't create top-level variables.
        if !self.may_add_ident() {
            if param_ids.len() > args.len() {
                log_abort!("iife: [x] Cannot inline because of too few arguments");
                return false;
            }

            for (pid, arg) in param_ids.clone().zip(args.iter()) {
                if let Some(usage) = self.data.vars.get(&pid.to_id()) {
                    if usage.ref_count > 1
                        || usage.assign_count > 0
                        || usage.flags.contains(VarUsageInfoFlags::INLINE_PREVENTED)
                        || !matches!(
                            &*arg.expr,
                            Expr::Lit(
                                Lit::Num(..) | Lit::Str(..) | Lit::Bool(..) | Lit::BigInt(..)
                            )
                        )
                    {
                        log_abort!("iife: [x] Cannot inline because of usage of `{}`", pid);
                        return false;
                    }
                }
            }
        }

        for pid in param_ids {
            if self.ident_reserved(&pid.sym) {
                log_abort!(
                    "iife: [x] Cannot inline because of reservation of `{}`",
                    pid
                );
                return false;
            }
        }

        true
    }

    fn can_inline_fn_stmt(&self, stmt: &Stmt, for_stmt: bool) -> bool {
        match stmt {

Review comment (suggestion):
The literal type check should include `Lit::Null(..)` to be consistent with other parts of the codebase. In other optimization functions like `inline.rs` and `sequences.rs`, null literals are treated as safe, side-effect-free values that can be inlined without creating variables. Omitting null from this check may unnecessarily prevent valid IIFE inlining optimizations when null is passed as an argument.
```suggestion
                                Lit::Num(..)
                                    | Lit::Str(..)
                                    | Lit::Bool(..)
                                    | Lit::BigInt(..)
                                    | Lit::Null(..)
```

Code after:
    fn can_inline_fn_arg(usage: &VarUsageInfo, arg: &Expr) -> bool {
        if usage.ref_count > 1
            || usage.assign_count > 0
            || usage.property_mutation_count > 0
            || usage.flags.contains(VarUsageInfoFlags::REASSIGNED)
            || usage.flags.contains(VarUsageInfoFlags::INLINE_PREVENTED)
        {
            return false;
        }

        match arg {
            Expr::Lit(
                Lit::Num(..) | Lit::Str(..) | Lit::Bool(..) | Lit::Null(..) | Lit::BigInt(..),
            ) => true,
            Expr::Fn(..) | Expr::Arrow(..) if usage.can_inline_fn_once() => true,
            _ => false,
        }
    }

    fn can_extract_param<'a>(
        &self,
        param_ids: impl ExactSizeIterator<Item = &'a Ident> + Clone,
        args: &[ExprOrSpread],
    ) -> bool {
        // Don't create top-level variables.
        if !self.may_add_ident() {
            for (idx, pid) in param_ids.clone().enumerate() {
                if let Some(usage) = self.data.vars.get(&pid.to_id()) {
                    let arg = args.get(idx).map(|a| &*a.expr);

                    if !arg
                        .map(|a| Self::can_inline_fn_arg(usage, a))
                        .unwrap_or(false)
                    {
                        log_abort!("iife: [x] Cannot inline because of usage of `{}`", pid);
                        return false;
                    }
                }
            }
        }

        for pid in param_ids {
            if self.ident_reserved(&pid.sym) {
                log_abort!(
                    "iife: [x] Cannot inline because of reservation of `{}`",
                    pid
                );
                return false;
            }
        }