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>)
| 1082 | /// |
| 1083 | /// Mirrors TreeSitterExtractor's curriedWrapperBoundName. |
| 1084 | fn curried_wrapper_bound_name(&self, node: Node<'t>) -> Option<String> { |
| 1085 | if !matches!( |
| 1086 | node.kind(), |
| 1087 | "arrow_function" | "function_expression" | "generator_function" |
| 1088 | ) { |
| 1089 | return None; |
| 1090 | } |
| 1091 | let args = node.parent()?; |
| 1092 | if args.kind() != "arguments" { |
| 1093 | return None; |
| 1094 | } |
| 1095 | let first = args.named_child(0)?; |
| 1096 | if first.start_byte() != node.start_byte() || first.end_byte() != node.end_byte() { |
| 1097 | return None; |
| 1098 | } |
| 1099 | let call = args.parent()?; |
| 1100 | if call.kind() != "call_expression" { |
| 1101 | return None; |
| 1102 | } |
| 1103 | // The bound that replaces the hook allowlist: the thing being called |
| 1104 | // is itself a call, so this is a curried wrapper's second application. |
| 1105 | let callee = call.child_by_field_name("function")?; |
| 1106 | if callee.kind() != "call_expression" { |
| 1107 | return None; |
| 1108 | } |
| 1109 | let binder = call.parent()?; |
| 1110 | // `{ getMode: Effect.fn("…")(function* () {…}) }`: an object member is |
| 1111 | // named by its property key, as extract_object_literal_functions names |
| 1112 | // `key: () => {}`. |
| 1113 | if binder.kind() == "pair" { |
| 1114 | let key = binder.child_by_field_name("key")?; |
| 1115 | let value = binder.child_by_field_name("value")?; |
| 1116 | if value.start_byte() != call.start_byte() || value.end_byte() != call.end_byte() { |
| 1117 | return None; |
| 1118 | } |
| 1119 | return Some(util::object_key_name(self.text(key))); |
| 1120 | } |
| 1121 | if binder.kind() != "variable_declarator" { |
| 1122 | return None; |
| 1123 | } |
| 1124 | let name_node = binder.child_by_field_name("name")?; |
| 1125 | if name_node.kind() != "identifier" { |
| 1126 | return None; |
| 1127 | } |
| 1128 | Some(self.text(name_node).to_string()) |
| 1129 | } |
| 1130 | |
| 1131 | /// extractName / extractNameRaw for the TS/JS configs. |
| 1132 | fn extract_name(&self, node: Node) -> String { |
no test coverage detected