Skip to content

Commit

Permalink
refactor(transformer): reorder match arms in JSX transform
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 18, 2024
1 parent 23d1bc6 commit f7750c0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions crates/oxc_transformer/src/react/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down

0 comments on commit f7750c0

Please sign in to comment.