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

Method extract_variable

codegraph-kernel/src/tsjs/extractors.rs:296–431  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

294 // --- extractVariable (TS/JS branch) ------------------------------------------------
295
296 pub(super) fn extract_variable(&mut self, node: Node<'t>) {
297 let is_const = self.is_const_decl(node);
298 let kind: &'static str = if is_const { "constant" } else { "variable" };
299 let docstring = crate::docstring::preceding_docstring(node, self.src);
300 let is_exported = self.is_exported(node); // `?? false` — always present
301
302 for i in 0..node.named_child_count() {
303 let Some(child) = node.named_child(i) else { continue };
304 if child.kind() != "variable_declarator" {
305 continue;
306 }
307 let Some(name_node) = child.child_by_field_name("name") else { continue };
308 let value = child.child_by_field_name("value");
309
310 // Destructured patterns are skipped — except RTK Query generated
311 // hooks (`export const { useGetXQuery } = api`).
312 if matches!(name_node.kind(), "object_pattern" | "array_pattern") {
313 if name_node.kind() == "object_pattern"
314 && value.map(|v| v.kind() == "identifier").unwrap_or(false)
315 {
316 self.extract_rtk_hook_bindings(name_node, is_exported);
317 }
318 continue;
319 }
320 let name = self.text(name_node).to_string();
321
322 // Arrow/function values extract as functions, named by the declarator.
323 if let Some(v) = value {
324 if matches!(v.kind(), "arrow_function" | "function_expression") {
325 self.extract_function(v, None);
326 continue;
327 }
328 }
329
330 let init_signature = value.map(|v| util::init_signature(self.text(v)));
331
332 // React HOC-wrapped components (#841), PascalCase-gated.
333 if let Some(v) = value {
334 if util::pascal_case().is_match(&name) {
335 if let Some(inner) = self.react_component_hoc(v) {
336 self.extract_react_component_node(
337 &name,
338 child,
339 inner,
340 Extra {
341 docstring: docstring.clone(),
342 signature: init_signature.clone(),
343 is_exported: Some(is_exported),
344 ..Extra::default()
345 },
346 );
347 continue;
348 }
349 }
350 }
351
352 let var_row = self.create_node(
353 kind,

Callers 1

visit_nodeMethod · 0.45

Tested by

no test coverage detected