From 24f09a4651df290c39494d6fc8a170a98ec9bfe7 Mon Sep 17 00:00:00 2001 From: lauren Date: Tue, 29 Oct 2024 18:07:27 -0400 Subject: [PATCH] [compiler] Check if local identifier is a hook when resolving globals When resolving import specifiers from the react namespace (`import {imported as local} from 'react'`), we were previously only checking if the `imported` identifier was a hook if we didn't already have its definition in the global registry. We also need to check if `local` is a hook in the case of aliasing since there may be hook-like APIs in react that don't start with `use` (eg they are experimental or unstable). --- .../babel-plugin-react-compiler/src/HIR/Environment.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts index b85d9425cb..c2918121d2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts @@ -852,7 +852,9 @@ export class Environment { */ return ( this.#globals.get(binding.imported) ?? - (isHookName(binding.imported) ? this.#getCustomHookType() : null) + (isHookName(binding.imported) || isHookName(binding.name) + ? this.#getCustomHookType() + : null) ); } else { const moduleType = this.#resolveModuleType(binding.module, loc);