From 23d1bc6ae25b1f67cecfc53e639cf9a4045a0cd3 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Wed, 18 Sep 2024 14:55:41 +0100 Subject: [PATCH] refactor(transformer): simplify match in JSX transform --- crates/oxc_transformer/src/react/jsx.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/oxc_transformer/src/react/jsx.rs b/crates/oxc_transformer/src/react/jsx.rs index 91fcc1d93e61cd..a6983b3a217641 100644 --- a/crates/oxc_transformer/src/react/jsx.rs +++ b/crates/oxc_transformer/src/react/jsx.rs @@ -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) => { @@ -496,7 +496,6 @@ impl<'a> ReactJsx<'a> { } } } - JSXAttributeItem::SpreadAttribute(_) => {} } // Add attribute to prop object