Returns the initializers it walked under the symbol they declare — a constant's or a variable's (#693), a component wrapper's — whose fn-ref candidates that walk already took for the symbol (the caller's scan of the declaration skips them; it would take each again for the file). Mirrors TreeSitterExtractor.extractVariable.
(&mut self, node: Node<'t>)
| 642 | /// the declaration skips them; it would take each again for the file). |
| 643 | /// Mirrors TreeSitterExtractor.extractVariable. |
| 644 | pub(super) fn extract_variable(&mut self, node: Node<'t>) -> Option<HashSet<usize>> { |
| 645 | let mut walked: Option<HashSet<usize>> = None; |
| 646 | let is_const = self.is_const_decl(node); |
| 647 | let kind: &'static str = if is_const { "constant" } else { "variable" }; |
| 648 | let docstring = crate::docstring::preceding_docstring(node, self.src); |
| 649 | let is_exported = self.is_exported(node); // `?? false` — always present |
| 650 | |
| 651 | for i in 0..node.named_child_count() { |
| 652 | let Some(child) = node.named_child(i) else { continue }; |
| 653 | if child.kind() != "variable_declarator" { |
| 654 | continue; |
| 655 | } |
| 656 | let Some(name_node) = child.child_by_field_name("name") else { continue }; |
| 657 | let value = child.child_by_field_name("value"); |
| 658 | |
| 659 | // Destructured patterns mint no node — except RTK Query generated |
| 660 | // hooks (`export const { useGetXQuery } = api`). |
| 661 | if matches!(name_node.kind(), "object_pattern" | "array_pattern") { |
| 662 | if name_node.kind() == "object_pattern" |
| 663 | && value.map(|v| v.kind() == "identifier").unwrap_or(false) |
| 664 | { |
| 665 | self.extract_rtk_hook_bindings(name_node, is_exported); |
| 666 | } |
| 667 | // The initializer (and any default in the pattern) still runs: |
| 668 | // walk the declarator as a function body walks it, with the |
| 669 | // enclosing scope on the stack (#2340). Mirrors |
| 670 | // TreeSitterExtractor.extractVariable. |
| 671 | self.visit_function_body(child); |
| 672 | continue; |
| 673 | } |
| 674 | let name = self.text(name_node).to_string(); |
| 675 | |
| 676 | // Arrow/function/generator values extract as functions, named by the declarator. |
| 677 | if let Some(v) = value { |
| 678 | if matches!(v.kind(), "arrow_function" | "function_expression" | "generator_function") { |
| 679 | self.extract_function(v, None); |
| 680 | continue; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | let init_signature = value.map(|v| util::init_signature(self.text(v))); |
| 685 | |
| 686 | // React HOC-wrapped components (#841), PascalCase-gated. |
| 687 | if let Some(v) = value { |
| 688 | if util::pascal_case().is_match(&name) { |
| 689 | if let Some(inner) = self.react_component_hoc(v) { |
| 690 | self.extract_react_component_node( |
| 691 | &name, |
| 692 | child, |
| 693 | inner, |
| 694 | Extra { |
| 695 | docstring: docstring.clone(), |
| 696 | signature: init_signature.clone(), |
| 697 | is_exported: Some(is_exported), |
| 698 | ..Extra::default() |
| 699 | }, |
| 700 | ); |
| 701 | if inner.is_none() { |
no test coverage detected