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

Method react_hook_bound_name

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

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

Source from the content-addressed store, hash-verified

1031 /// must be the call's FIRST argument and the call's value must be bound
1032 /// directly by a `variable_declarator`.
1033 fn react_hook_bound_name(&self, node: Node<'t>) -> Option<String> {
1034 if !matches!(node.kind(), "arrow_function" | "function_expression") {
1035 return None;
1036 }
1037 let args = node.parent()?;
1038 if args.kind() != "arguments" {
1039 return None;
1040 }
1041 let first = args.named_child(0)?;
1042 if first.start_byte() != node.start_byte() || first.end_byte() != node.end_byte() {
1043 return None;
1044 }
1045 let call = args.parent()?;
1046 if call.kind() != "call_expression" {
1047 return None;
1048 }
1049 let callee = call.child_by_field_name("function")?;
1050 let callee_text = self.text(callee);
1051 let hook = callee_text.strip_prefix("React.").unwrap_or(callee_text);
1052 if !matches!(hook, "useCallback" | "useEffectEvent" | "useEvent") {
1053 return None;
1054 }
1055 let declarator = call.parent()?;
1056 if declarator.kind() != "variable_declarator" {
1057 return None;
1058 }
1059 let name_node = declarator.child_by_field_name("name")?;
1060 if name_node.kind() != "identifier" {
1061 return None;
1062 }
1063 Some(self.text(name_node).to_string())
1064 }
1065
1066 /// The declarator name for an anonymous function passed to a CURRIED
1067 /// wrapper call — `const NAME = factory(...)(function () {…})` — or the

Callers 1

Calls 1

textMethod · 0.65

Tested by

no test coverage detected