From d2eaa7dd4132e71a564816a6dad17e493314d237 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 19 Sep 2024 06:19:11 +0000 Subject: [PATCH] refactor(transformer): reorder match arms in JSX transform (#5860) Pure refactor. Switch order of code. Spread attributes are more unusual than standard attributes, so put the common case first. --- crates/oxc_transformer/src/react/jsx.rs | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/oxc_transformer/src/react/jsx.rs b/crates/oxc_transformer/src/react/jsx.rs index a6983b3a2..f578e0c69 100644 --- a/crates/oxc_transformer/src/react/jsx.rs +++ b/crates/oxc_transformer/src/react/jsx.rs @@ -463,20 +463,6 @@ impl<'a> ReactJsx<'a> { let attributes = &e.opening_element.attributes; 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::Attribute(attr) => { if attr.is_identifier("__self") { self_attr_span = Some(attr.name.span()); @@ -496,6 +482,20 @@ impl<'a> ReactJsx<'a> { } } } + // 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; + } + } + } } // Add attribute to prop object