mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(transformer): simplify match in JSX transform (#5859)
Pure refactor. Reduce match to 1 arm per variant.
This commit is contained in:
parent
a111bb69af
commit
58a83274fd
1 changed files with 11 additions and 12 deletions
|
|
@ -464,17 +464,17 @@ impl<'a> ReactJsx<'a> {
|
||||||
for attribute in attributes {
|
for attribute in attributes {
|
||||||
match attribute {
|
match attribute {
|
||||||
// optimize `{...prop}` to `prop` in static mode
|
// optimize `{...prop}` to `prop` in static mode
|
||||||
JSXAttributeItem::SpreadAttribute(spread)
|
JSXAttributeItem::SpreadAttribute(spread) => {
|
||||||
if is_classic && attributes.len() == 1 =>
|
if is_classic && attributes.len() == 1 {
|
||||||
{
|
// deopt if spreading an object with `__proto__` key
|
||||||
// deopt if spreading an object with `__proto__` key
|
if !matches!(&spread.argument, Expression::ObjectExpression(o) if o.has_proto())
|
||||||
if !matches!(&spread.argument, Expression::ObjectExpression(o) if o.has_proto())
|
{
|
||||||
{
|
arguments.push(Argument::from({
|
||||||
arguments.push(Argument::from({
|
// SAFETY: `ast.copy` is unsound! We need to fix.
|
||||||
// SAFETY: `ast.copy` is unsound! We need to fix.
|
unsafe { self.ast().copy(&spread.argument) }
|
||||||
unsafe { self.ast().copy(&spread.argument) }
|
}));
|
||||||
}));
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSXAttributeItem::Attribute(attr) => {
|
JSXAttributeItem::Attribute(attr) => {
|
||||||
|
|
@ -496,7 +496,6 @@ impl<'a> ReactJsx<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSXAttributeItem::SpreadAttribute(_) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add attribute to prop object
|
// Add attribute to prop object
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue