MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / curried_wrapper_bound_name

Method curried_wrapper_bound_name

codegraph-kernel/src/tsjs/mod.rs:976–1021  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

974 ///
975 /// Mirrors TreeSitterExtractor's curriedWrapperBoundName.
976 fn curried_wrapper_bound_name(&self, node: Node<'t>) -> Option<String> {
977 if !matches!(
978 node.kind(),
979 "arrow_function" | "function_expression" | "generator_function"
980 ) {
981 return None;
982 }
983 let args = node.parent()?;
984 if args.kind() != "arguments" {
985 return None;
986 }
987 let first = args.named_child(0)?;
988 if first.start_byte() != node.start_byte() || first.end_byte() != node.end_byte() {
989 return None;
990 }
991 let call = args.parent()?;
992 if call.kind() != "call_expression" {
993 return None;
994 }
995 // The bound that replaces the hook allowlist: the thing being called
996 // is itself a call, so this is a curried wrapper's second application.
997 let callee = call.child_by_field_name("function")?;
998 if callee.kind() != "call_expression" {
999 return None;
1000 }
1001 let binder = call.parent()?;
1002 // `{ getMode: Effect.fn("…")(function* () {…}) }`: an object member is
1003 // named by its property key, as extract_object_literal_functions names
1004 // `key: () => {}`.
1005 if binder.kind() == "pair" {
1006 let key = binder.child_by_field_name("key")?;
1007 let value = binder.child_by_field_name("value")?;
1008 if value.start_byte() != call.start_byte() || value.end_byte() != call.end_byte() {
1009 return None;
1010 }
1011 return Some(util::object_key_name(self.text(key)));
1012 }
1013 if binder.kind() != "variable_declarator" {
1014 return None;
1015 }
1016 let name_node = binder.child_by_field_name("name")?;
1017 if name_node.kind() != "identifier" {
1018 return None;
1019 }
1020 Some(self.text(name_node).to_string())
1021 }
1022
1023 /// extractName / extractNameRaw for the TS/JS configs.
1024 fn extract_name(&self, node: Node) -> String {

Calls 2

object_key_nameFunction · 0.85
textMethod · 0.65

Tested by

no test coverage detected