Skip to content

Commit

Permalink
refactor(transformer): simplify match in JSX transform (#5859)
Browse files Browse the repository at this point in the history
Pure refactor. Reduce match to 1 arm per variant.
  • Loading branch information
overlookmotel committed Sep 19, 2024
1 parent a111bb6 commit 58a8327
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions crates/oxc_transformer/src/react/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,17 @@ impl<'a> ReactJsx<'a> {
for attribute in attributes {
match attribute {
// optimize `{...prop}` to `prop` in static mode
JSXAttributeItem::SpreadAttribute(spread)
if is_classic && attributes.len() == 1 =>
{
// deopt if spreading an object with `__proto__` key
if !matches!(&spread.argument, Expression::ObjectExpression(o) if o.has_proto())
{
arguments.push(Argument::from({
// SAFETY: `ast.copy` is unsound! We need to fix.
unsafe { self.ast().copy(&spread.argument) }
}));
continue;
JSXAttributeItem::SpreadAttribute(spread) => {
if is_classic && attributes.len() == 1 {
// deopt if spreading an object with `__proto__` key
if !matches!(&spread.argument, Expression::ObjectExpression(o) if o.has_proto())
{
arguments.push(Argument::from({
// SAFETY: `ast.copy` is unsound! We need to fix.
unsafe { self.ast().copy(&spread.argument) }
}));
continue;
}
}
}
JSXAttributeItem::Attribute(attr) => {
Expand All @@ -496,7 +496,6 @@ impl<'a> ReactJsx<'a> {
}
}
}
JSXAttributeItem::SpreadAttribute(_) => {}
}

// Add attribute to prop object
Expand Down

0 comments on commit 58a8327

Please sign in to comment.