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

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

Review comment (bug):
The condition `usage.property_mutation_count == 0` check was removed from the inlining logic in `inline_fn_param_stmt`. Previously, the code checked this condition before inlining, but now `can_inline_fn_arg` doesn't verify property mutations. This could potentially lead to incorrect inlining when the parameter has property mutations. Consider adding this check to the `can_inline_fn_arg` function to maintain the same safety guarantees.

Code after:
                    && 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;
                    }
                }
            }
        }

        for pid in param_ids {
            if self.ident_reserved(&pid.sym) {