Repository: swc-project/swc
File: crates/swc_ecma_transformer/src/es2017/async_to_generator.rs (Rust)

Code before:
        | Expr::TsSatisfies(_)
        | Expr::MetaProp(_)
        | Expr::Invalid(_) => {}
        #[cfg(swc_ast_unknown)]
        _ => {}
    }
}

fn replace_this_in_member_expr(member: &mut MemberExpr, this_var: &Ident) {
    replace_this_in_expr(&mut member.obj, this_var);
    if let MemberProp::Computed(computed) = &mut member.prop {
        replace_this_in_expr(&mut computed.expr, this_var);
    }
}

fn replace_this_in_opt_chain_base(base: &mut OptChainBase, this_var: &Ident) {
    match base {
        OptChainBase::Member(member) => {
            replace_this_in_expr(&mut member.obj, this_var);
            if let MemberProp::Computed(computed) = &mut member.prop {
                replace_this_in_expr(&mut computed.expr, this_var);
            }
        }
        OptChainBase::Call(call) => {
            replace_this_in_expr(&mut call.callee, this_var);
            for arg in &mut call.args {
                replace_this_in_expr(&mut arg.expr, this_var);
            }
        }
        #[cfg(swc_ast_unknown)]
        _ => {}
    }
}

fn replace_this_in_pat(pat: &mut AssignTargetPat, this_var: &Ident) {
    match pat {
        AssignTargetPat::Array(array) => {
            for elem in array.elems.iter_mut().flatten() {
                replace_this_in_pat_inner(elem, this_var);
            }
        }
        AssignTargetPat::Object(obj) => {
            for prop in &mut obj.props {
                match prop {
                    ObjectPatProp::KeyValue(kv) => {
                        if let PropName::Computed(computed) = &mut kv.key {
                            replace_this_in_expr(&mut computed.expr, this_var);
                        }
                        replace_this_in_pat_inner(&mut kv.value, this_var);
                    }
                    ObjectPatProp::Assign(assign) => {

Review comment (refactor):
The `OptChainBase::Member` case duplicates the exact same logic as `replace_this_in_member_expr`. Consider calling `replace_this_in_member_expr(member, this_var)` here to eliminate the duplication and improve maintainability.
```suggestion
            replace_this_in_member_expr(member, this_var);
```

Code after:
        | Expr::TsAs(_)
        | Expr::TsInstantiation(_)
        | Expr::TsSatisfies(_)
        | Expr::MetaProp(_)
        | Expr::Invalid(_) => {}
        #[cfg(swc_ast_unknown)]
        _ => {}
    }
}

fn replace_this_in_member_expr(member: &mut MemberExpr, this_var: &Ident) {
    replace_this_in_expr(&mut member.obj, this_var);
    if let MemberProp::Computed(computed) = &mut member.prop {
        replace_this_in_expr(&mut computed.expr, this_var);
    }
}

fn replace_this_in_opt_chain_base(base: &mut OptChainBase, this_var: &Ident) {
    match base {
        OptChainBase::Member(member) => {
            replace_this_in_expr(&mut member.obj, this_var);
            if let MemberProp::Computed(computed) = &mut member.prop {
                replace_this_in_expr(&mut computed.expr, this_var);
            }
        }
        OptChainBase::Call(call) => {
            replace_this_in_expr(&mut call.callee, this_var);
            for arg in &mut call.args {
                replace_this_in_expr(&mut arg.expr, this_var);
            }
        }
        #[cfg(swc_ast_unknown)]
        _ => {}
    }
}

fn replace_this_in_pat(pat: &mut AssignTargetPat, this_var: &Ident) {
    match pat {
        AssignTargetPat::Array(array) => {
            for elem in array.elems.iter_mut().flatten() {
                replace_this_in_pat_inner(elem, this_var);
            }
        }
        AssignTargetPat::Object(obj) => {
            for prop in &mut obj.props {
                match prop {
                    ObjectPatProp::KeyValue(kv) => {
                        if let PropName::Computed(computed) = &mut kv.key {
                            replace_this_in_expr(&mut computed.expr, this_var);
                        }
                        replace_this_in_pat_inner(&mut kv.value, this_var);