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

Code before:
                self.is_return_arg_simple_enough_for_iife_eval(&e.left)
                    && self.is_return_arg_simple_enough_for_iife_eval(&e.right)
            }

            Expr::Cond(e) => {
                self.is_return_arg_simple_enough_for_iife_eval(&e.test)
                    && self.is_return_arg_simple_enough_for_iife_eval(&e.cons)
                    && self.is_return_arg_simple_enough_for_iife_eval(&e.alt)
            }

            _ => false,
        }
    }

    fn can_inline_fn_arg(usage: &VarUsageInfo, arg: &Expr) -> bool {
        if usage.ref_count > 1
            || usage.assign_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::BigInt(..)) => true,
            Expr::Fn(..) 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;
                    }
                }
            }
        }

Review comment (suggestion):
The function only checks `Expr::Fn(..)` for the `can_inline_fn_once()` condition, but arrow functions (`Expr::Arrow(..)`) should also be considered. Other parts of the codebase (e.g., in inline.rs) treat both function expressions and arrow functions together when checking if they can be inlined. Consider adding `Expr::Arrow(..)` to this match arm to ensure consistent behavior.
```suggestion
            Expr::Fn(..) | Expr::Arrow(..) if usage.can_inline_fn_once() => true,
```

Code after:
                self.is_return_arg_simple_enough_for_iife_eval(&e.left)
                    && self.is_return_arg_simple_enough_for_iife_eval(&e.right)
            }

            Expr::Cond(e) => {
                self.is_return_arg_simple_enough_for_iife_eval(&e.test)
                    && self.is_return_arg_simple_enough_for_iife_eval(&e.cons)
                    && self.is_return_arg_simple_enough_for_iife_eval(&e.alt)
            }

            _ => false,
        }
    }

    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;
                    }