Repository: swc-project/swc
File: crates/swc_ecma_transformer/src/es2021/logical_assignment_operators.rs (Rust)

Code before:

                (left_prop, right_prop)
            }
            // Static properties don't need temp vars
            prop => (prop.clone(), prop.clone()),
        };

        // Build left expression: `(_a = a).b` or `(_a = a)[_b = b]`
        let left_expr = Box::new(Expr::Member(MemberExpr {
            span: member_expr.span,
            obj: left_obj,
            prop: left_prop,
        }));

        // Build assignment target: `_a.b` or `_a[_b]`
        let assign_target = SimpleAssignTarget::Member(MemberExpr {
            span: member_expr.span,
            obj: right_obj,
            prop: right_prop,
        });

        (left_expr, assign_target)
    }

    fn transform_super_prop(
        &mut self,
        super_prop_expr: &mut SuperPropExpr,
        ctx: &mut TraverseCtx,
    ) -> (Box<Expr>, SimpleAssignTarget) {
        let (left_prop, right_prop) = match &super_prop_expr.prop {
            SuperProp::Computed(computed) => {
                let alias = alias_ident_for(&computed.expr, "_ref");

                // Inject variable declaration
                self.inject_var_decl(&alias, ctx);

                let left_prop = SuperProp::Computed(ComputedPropName {
                    span: computed.span,
                    expr: Box::new(Expr::Assign(AssignExpr {
                        span: DUMMY_SP,
                        op: AssignOp::Assign,
                        left: AssignTarget::Simple(SimpleAssignTarget::Ident(BindingIdent {
                            id: alias.clone(),
                            type_ann: None,
                        })),
                        right: computed.expr.clone(),
                    })),
                });

                let right_prop = SuperProp::Computed(ComputedPropName {
                    span: computed.span,

Review comment (suggestion):
The `super_prop_expr.obj` field is being moved twice (lines 295 and 301), which will cause a compilation error. Since `Super` is a `Copy` type, you should use `super_prop_expr.obj` directly in both places rather than moving it. The correct approach is to simply reference it without taking ownership.

Code after:
                    })),
                });

                let right_prop = SuperProp::Computed(ComputedPropName {
                    span: computed.span,
                    expr: Box::new(Expr::Ident(alias)),
                });

                (left_prop, right_prop)
            }
            prop => (prop.clone(), prop.clone()),
        };

        let left_expr = Box::new(Expr::SuperProp(SuperPropExpr {
            span: super_prop_expr.span,
            obj: super_prop_expr.obj,
            prop: left_prop,
        }));

        let assign_target = SimpleAssignTarget::SuperProp(SuperPropExpr {
            span: super_prop_expr.span,
            obj: super_prop_expr.obj,
            prop: right_prop,
        });

        (left_expr, assign_target)
    }

    fn inject_var_decl(&mut self, ident: &Ident, ctx: &mut TraverseCtx) {
        let decl = VarDeclarator {
            span: DUMMY_SP,
            name: Pat::Ident(BindingIdent {
                id: ident.clone(),
                type_ann: None,
            }),
            init: None,
            definite: false,
        };

        ctx.statement_injector.insert_before(
            self.stmt_ptr.unwrap(),
            VarDecl {
                kind: VarDeclKind::Var,
                decls: vec![decl],
                ..Default::default()
            }
            .into(),
        );
    }
}