The declarator name for an anonymous function passed to a CURRIED wrapper call — `const NAME = factory(...)(function () {…})` — or the property key when the call is an object member, `{ NAME: factory(...)(fn) }`; else None. `react_hook_bound_name` above names a function through the declarator that binds it; the shape is general, but that method is bounded to the three React handler hooks. This is
(&self, node: Node<'t>)
| 968 | /// |
| 969 | /// Mirrors TreeSitterExtractor's curriedWrapperBoundName. |
| 970 | fn curried_wrapper_bound_name(&self, node: Node<'t>) -> Option<String> { |
| 971 | if !matches!( |
| 972 | node.kind(), |
| 973 | "arrow_function" | "function_expression" | "generator_function" |
| 974 | ) { |
| 975 | return None; |
| 976 | } |
| 977 | let args = node.parent()?; |
| 978 | if args.kind() != "arguments" { |
| 979 | return None; |
| 980 | } |
| 981 | let first = args.named_child(0)?; |
| 982 | if first.start_byte() != node.start_byte() || first.end_byte() != node.end_byte() { |
| 983 | return None; |
| 984 | } |
| 985 | let call = args.parent()?; |
| 986 | if call.kind() != "call_expression" { |
| 987 | return None; |
| 988 | } |
| 989 | // The bound that replaces the hook allowlist: the thing being called |
| 990 | // is itself a call, so this is a curried wrapper's second application. |
| 991 | let callee = call.child_by_field_name("function")?; |
| 992 | if callee.kind() != "call_expression" { |
| 993 | return None; |
| 994 | } |
| 995 | let binder = call.parent()?; |
| 996 | // `{ getMode: Effect.fn("…")(function* () {…}) }`: an object member is |
| 997 | // named by its property key, as extract_object_literal_functions names |
| 998 | // `key: () => {}`. |
| 999 | if binder.kind() == "pair" { |
| 1000 | let key = binder.child_by_field_name("key")?; |
| 1001 | let value = binder.child_by_field_name("value")?; |
| 1002 | if value.start_byte() != call.start_byte() || value.end_byte() != call.end_byte() { |
| 1003 | return None; |
| 1004 | } |
| 1005 | return Some(util::object_key_name(self.text(key))); |
| 1006 | } |
| 1007 | if binder.kind() != "variable_declarator" { |
| 1008 | return None; |
| 1009 | } |
| 1010 | let name_node = binder.child_by_field_name("name")?; |
| 1011 | if name_node.kind() != "identifier" { |
| 1012 | return None; |
| 1013 | } |
| 1014 | Some(self.text(name_node).to_string()) |
| 1015 | } |
| 1016 | |
| 1017 | /// extractName / extractNameRaw for the TS/JS configs. |
| 1018 | fn extract_name(&self, node: Node) -> String { |
no test coverage detected