Repository: swc-project/swc
File: crates/swc_ecma_compat_es2015/src/spread.rs (Rust)

Code before:
                                }
                                .as_arg(),
                            );
                            current_elems = Vec::new();
                        }
                        // Special handling for `arguments` to call Array.prototype.slice
                        // https://github.com/babel/babel/blob/61ad8555b875cb0c0996f18f803b6bf1d2150173/packages/babel-plugin-transform-spread/src/index.ts#L43-L47
                        let expr = match *expr {
                            Expr::Ident(Ident { ref sym, ctxt, .. })
                                if &**sym == "arguments"
                                    && (ctxt == self.unresolved_ctxt
                                        || ctxt == SyntaxContext::empty()) =>
                            {
                                CallExpr {
                                    span,
                                    callee: member_expr!(
                                        Default::default(),
                                        DUMMY_SP,
                                        Array.prototype.slice.call
                                    )
                                    .as_callee(),
                                    args: vec![expr.as_arg()],
                                    ..Default::default()
                                }
                                .into()
                            }
                            _ => *expr,
                        };
                        arg_list.push(expr.as_arg());
                    }
                    None => {
                        current_elems.push(Some(expr.as_arg()));
                    }
                }
            }
            if !current_elems.is_empty() {
                arg_list.push(
                    ArrayLit {
                        span: DUMMY_SP,
                        elems: current_elems,
                    }
                    .as_arg(),
                );
            }

            return CallExpr {
                span: DUMMY_SP,
                callee: ArrayLit {
                    span: DUMMY_SP,
                    elems: Vec::new(),
                }

Review comment (bug):
The condition `|| ctxt == SyntaxContext::empty()` may be too permissive and could incorrectly match user-defined variables named 'arguments'. Consider removing this fallback or adding more specific context validation.

Code after:
                                }
                                .as_arg(),
                            );
                            current_elems = Vec::new();
                        }
                        // Special handling for `arguments` to call Array.prototype.slice
                        // https://github.com/babel/babel/blob/61ad8555b875cb0c0996f18f803b6bf1d2150173/packages/babel-plugin-transform-spread/src/index.ts#L43-L47
                        let expr = match *expr {
                            Expr::Ident(Ident { ref sym, ctxt, .. })
                                if &**sym == "arguments" && ctxt == self.unresolved_ctxt =>
                            {
                                CallExpr {
                                    span,
                                    callee: member_expr!(
                                        Default::default(),
                                        DUMMY_SP,
                                        Array.prototype.slice.call
                                    )
                                    .as_callee(),
                                    args: vec![expr.as_arg()],
                                    ..Default::default()
                                }
                                .into()
                            }
                            _ => *expr,
                        };
                        arg_list.push(expr.as_arg());
                    }
                    None => {
                        current_elems.push(Some(expr.as_arg()));
                    }
                }
            }
            if !current_elems.is_empty() {
                arg_list.push(
                    ArrayLit {
                        span: DUMMY_SP,
                        elems: current_elems,
                    }
                    .as_arg(),
                );
            }

            return CallExpr {
                span: DUMMY_SP,
                callee: ArrayLit {
                    span: DUMMY_SP,
                    elems: Vec::new(),
                }
                .make_member(quote_ident!("concat"))
                .as_callee(),