fix(transformer/react): should not collect use-hooks if it's a nested member expression (#6143)

close: #6139

I still remember this logic and I call `get_first_object` for it intentionally 🥲
This commit is contained in:
Dunqing 2024-09-28 14:38:14 +00:00
parent ab187d1e22
commit bfd19882b0
2 changed files with 3 additions and 2 deletions

View file

@ -384,10 +384,11 @@ impl<'a, 'ctx> Traverse<'a> for ReactRefresh<'a, 'ctx> {
}
if !is_builtin_hook(&hook_name) {
// Check if a corresponding binding exists where we emit the signature.
let (binding_name, is_member_expression) = match &call_expr.callee {
Expression::Identifier(ident) => (Some(ident.name.clone()), false),
Expression::StaticMemberExpression(member) => {
if let Expression::Identifier(object) = member.get_first_object() {
if let Expression::Identifier(object) = &member.object {
(Some(object.name.clone()), true)
} else {
(None, false)

View file

@ -3,7 +3,7 @@ export function Bar() {
_s();
A.B.C.useHook();
}
_s(Bar, "useHook{}", true);
_s(Bar, "useHook{}");
_c = Bar;
var _c;
$RefreshReg$(_c, "Bar");