The declarator name a React handler hook binds an anonymous function to — `const NAME = useCallback( , [...])` (also `React.useCallback`, `useEffectEvent`, `useEvent`) — or None for any other shape. The node must be the call's FIRST argument and the call's value must be bound directly by a `variable_declarator`.
(&self, node: Node<'t>)
| 917 | /// must be the call's FIRST argument and the call's value must be bound |
| 918 | /// directly by a `variable_declarator`. |
| 919 | fn react_hook_bound_name(&self, node: Node<'t>) -> Option<String> { |
| 920 | if !matches!(node.kind(), "arrow_function" | "function_expression") { |
| 921 | return None; |
| 922 | } |
| 923 | let args = node.parent()?; |
| 924 | if args.kind() != "arguments" { |
| 925 | return None; |
| 926 | } |
| 927 | let first = args.named_child(0)?; |
| 928 | if first.start_byte() != node.start_byte() || first.end_byte() != node.end_byte() { |
| 929 | return None; |
| 930 | } |
| 931 | let call = args.parent()?; |
| 932 | if call.kind() != "call_expression" { |
| 933 | return None; |
| 934 | } |
| 935 | let callee = call.child_by_field_name("function")?; |
| 936 | let callee_text = self.text(callee); |
| 937 | let hook = callee_text.strip_prefix("React.").unwrap_or(callee_text); |
| 938 | if !matches!(hook, "useCallback" | "useEffectEvent" | "useEvent") { |
| 939 | return None; |
| 940 | } |
| 941 | let declarator = call.parent()?; |
| 942 | if declarator.kind() != "variable_declarator" { |
| 943 | return None; |
| 944 | } |
| 945 | let name_node = declarator.child_by_field_name("name")?; |
| 946 | if name_node.kind() != "identifier" { |
| 947 | return None; |
| 948 | } |
| 949 | Some(self.text(name_node).to_string()) |
| 950 | } |
| 951 | |
| 952 | /// The declarator name for an anonymous function passed to a CURRIED |
| 953 | /// wrapper call — `const NAME = factory(...)(function () {…})` — or the |
no test coverage detected