Skip to content
21 changes: 16 additions & 5 deletions crates/oxc_transformer/src/es2018/object_rest_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,22 +561,33 @@ impl<'a> ObjectRestSpread<'a, '_> {
// Transform `(...x) => {}`.
fn transform_arrow(arrow: &mut ArrowFunctionExpression<'a>, ctx: &mut TraverseCtx<'a>) {
let scope_id = arrow.scope_id();
let mut replaced = false;
for param in &mut arrow.params.items {
if Self::has_nested_object_rest(&param.pattern) {
// `({ ...args }) => { args }`
if arrow.expression {
arrow.expression = false;

debug_assert!(arrow.body.statements.len() == 1);

let Statement::ExpressionStatement(stmt) = arrow.body.statements.pop().unwrap()
else {
unreachable!(
"`arrow.expression` is true, which means it has only one ExpressionStatement."
);
};
let return_stmt =
ctx.ast.statement_return(stmt.span, Some(stmt.unbox().expression));
arrow.body.statements.push(return_stmt);
}
Self::replace_rest_element(
VariableDeclarationKind::Var,
&mut param.pattern,
&mut arrow.body.statements,
scope_id,
ctx,
);
replaced = true;
}
}
if replaced && arrow.expression {
arrow.expression = false;
}
}

// Transform `try {} catch ({...x}) {}`.
Expand Down
2 changes: 1 addition & 1 deletion tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 1d4546bc

Passed: 178/296
Passed: 179/297

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const fn = ({ ...args }) => args;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fn = (_ref) => {
let args = babelHelpers.extends(
{},
(babelHelpers.objectDestructuringEmpty(_ref), _ref),
);
return args;
};
Loading