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>)
| 948 | /// |
| 949 | /// Mirrors TreeSitterExtractor's curriedWrapperBoundName. |
| 950 | fn curried_wrapper_bound_name(&self, node: Node<'t>) -> Option<String> { |
| 951 | if !matches!( |
| 952 | node.kind(), |
| 953 | "arrow_function" | "function_expression" | "generator_function" |
| 954 | ) { |
| 955 | return None; |
| 956 | } |
| 957 | let args = node.parent()?; |
| 958 | if args.kind() != "arguments" { |
| 959 | return None; |
| 960 | } |
| 961 | let first = args.named_child(0)?; |
| 962 | if first.start_byte() != node.start_byte() || first.end_byte() != node.end_byte() { |
| 963 | return None; |
| 964 | } |
| 965 | let call = args.parent()?; |
| 966 | if call.kind() != "call_expression" { |
| 967 | return None; |
| 968 | } |
| 969 | // The bound that replaces the hook allowlist: the thing being called |
| 970 | // is itself a call, so this is a curried wrapper's second application. |
| 971 | let callee = call.child_by_field_name("function")?; |
| 972 | if callee.kind() != "call_expression" { |
| 973 | return None; |
| 974 | } |
| 975 | let binder = call.parent()?; |
| 976 | // `{ getMode: Effect.fn("…")(function* () {…}) }`: an object member is |
| 977 | // named by its property key, as extract_object_literal_functions names |
| 978 | // `key: () => {}`. |
| 979 | if binder.kind() == "pair" { |
| 980 | let key = binder.child_by_field_name("key")?; |
| 981 | let value = binder.child_by_field_name("value")?; |
| 982 | if value.start_byte() != call.start_byte() || value.end_byte() != call.end_byte() { |
| 983 | return None; |
| 984 | } |
| 985 | return Some(util::object_key_name(self.text(key))); |
| 986 | } |
| 987 | if binder.kind() != "variable_declarator" { |
| 988 | return None; |
| 989 | } |
| 990 | let name_node = binder.child_by_field_name("name")?; |
| 991 | if name_node.kind() != "identifier" { |
| 992 | return None; |
| 993 | } |
| 994 | Some(self.text(name_node).to_string()) |
| 995 | } |
| 996 | |
| 997 | /// extractName / extractNameRaw for the TS/JS configs. |
| 998 | fn extract_name(&self, node: Node) -> String { |
no test coverage detected