mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(transformer/react-refresh): small refactor (#6973)
Follow-on after #6937. Refactor 2 small blocks of code. * Replace 2 `if` statements with 1. * Obey the mighty clippy!
This commit is contained in:
parent
610621cadf
commit
9e66c2949d
1 changed files with 19 additions and 18 deletions
|
|
@ -211,16 +211,19 @@ impl<'a, 'ctx> Traverse<'a> for ReactRefresh<'a, 'ctx> {
|
||||||
|
|
||||||
if !matches!(expr, Expression::CallExpression(_)) {
|
if !matches!(expr, Expression::CallExpression(_)) {
|
||||||
// Try to get binding from parent VariableDeclarator
|
// Try to get binding from parent VariableDeclarator
|
||||||
let id_binding = if let Ancestor::VariableDeclaratorInit(declarator) = ctx.parent() {
|
if let Ancestor::VariableDeclaratorInit(declarator) = ctx.parent() {
|
||||||
declarator.id().get_binding_identifier().map(BoundIdentifier::from_binding_ident)
|
if let Some(ident) = declarator.id().get_binding_identifier() {
|
||||||
} else {
|
let id_binding = BoundIdentifier::from_binding_ident(ident);
|
||||||
None
|
self.handle_function_in_variable_declarator(
|
||||||
};
|
&id_binding,
|
||||||
if let Some(id_binding) = id_binding {
|
&binding,
|
||||||
self.handle_function_in_variable_declarator(&id_binding, &binding, arguments, ctx);
|
arguments,
|
||||||
|
ctx,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut found_call_expression = false;
|
let mut found_call_expression = false;
|
||||||
for ancestor in ctx.ancestors() {
|
for ancestor in ctx.ancestors() {
|
||||||
|
|
@ -813,18 +816,16 @@ impl<'a, 'ctx> ReactRefresh<'a, 'ctx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get the address of the statement containing this `VariableDeclarator`
|
// Get the address of the statement containing this `VariableDeclarator`
|
||||||
#[allow(clippy::single_match_else)]
|
let address =
|
||||||
let address = match ctx.ancestor(2) {
|
if let Ancestor::ExportNamedDeclarationDeclaration(export_decl) = ctx.ancestor(2) {
|
||||||
// For `export const Foo = () => {}`
|
// For `export const Foo = () => {}`
|
||||||
// which is a `VariableDeclaration` inside a `Statement::ExportNamedDeclaration`
|
// which is a `VariableDeclaration` inside a `Statement::ExportNamedDeclaration`
|
||||||
Ancestor::ExportNamedDeclarationDeclaration(export_decl) => export_decl.address(),
|
export_decl.address()
|
||||||
// Otherwise just a `const Foo = () => {}`
|
} else {
|
||||||
// which is a `Statement::VariableDeclaration`
|
// Otherwise just a `const Foo = () => {}` which is a `Statement::VariableDeclaration`
|
||||||
_ => {
|
|
||||||
let var_decl = ctx.ancestor(1);
|
let var_decl = ctx.ancestor(1);
|
||||||
debug_assert!(matches!(var_decl, Ancestor::VariableDeclarationDeclarations(_)));
|
debug_assert!(matches!(var_decl, Ancestor::VariableDeclarationDeclarations(_)));
|
||||||
var_decl.address()
|
var_decl.address()
|
||||||
}
|
|
||||||
};
|
};
|
||||||
self.ctx.statement_injector.insert_after(&address, statement);
|
self.ctx.statement_injector.insert_after(&address, statement);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue