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>)
| 738 | /// the declaration skips them; it would take each again for the file). |
| 739 | /// Mirrors TreeSitterExtractor.extractVariable. |
| 740 | pub(super) fn extract_variable(&mut self, node: Node<'t>) -> Option<HashSet<usize>> { |
| 741 | let mut walked: Option<HashSet<usize>> = None; |
| 742 | let is_const = self.is_const_decl(node); |
| 743 | let kind: &'static str = if is_const { "constant" } else { "variable" }; |
| 744 | let docstring = crate::docstring::preceding_docstring(node, self.src); |
| 745 | let is_exported = self.is_exported(node); // `?? false` — always present |
| 746 | |
| 747 | for i in 0..node.named_child_count() { |
| 748 | let Some(child) = node.named_child(i) else { continue }; |
| 749 | if child.kind() != "variable_declarator" { |
| 750 | continue; |
| 751 | } |
| 752 | let Some(name_node) = child.child_by_field_name("name") else { continue }; |
| 753 | let value = child.child_by_field_name("value"); |
| 754 | |
| 755 | // Destructured patterns mint no node — except RTK Query generated |
| 756 | // hooks (`export const { useGetXQuery } = api`). |
| 757 | if matches!(name_node.kind(), "object_pattern" | "array_pattern") { |
| 758 | if name_node.kind() == "object_pattern" |
| 759 | && value.map(|v| v.kind() == "identifier").unwrap_or(false) |
| 760 | { |
| 761 | self.extract_rtk_hook_bindings(name_node, is_exported); |
| 762 | } |
| 763 | // The initializer (and any default in the pattern) still runs: |
| 764 | // walk the declarator as a function body walks it, with the |
| 765 | // enclosing scope on the stack (#2340). Mirrors |
| 766 | // TreeSitterExtractor.extractVariable. |
| 767 | self.visit_function_body(child); |
| 768 | continue; |
| 769 | } |
| 770 | let name = self.text(name_node).to_string(); |
| 771 | |
| 772 | // Arrow/function/generator values extract as functions, named by the declarator. |
| 773 | if let Some(v) = value { |
| 774 | if matches!(v.kind(), "arrow_function" | "function_expression" | "generator_function") { |
| 775 | self.extract_function(v, None); |
| 776 | continue; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | let init_signature = value.map(|v| util::init_signature(self.text(v))); |
| 781 | |
| 782 | // React HOC-wrapped components (#841), PascalCase-gated. |
| 783 | if let Some(v) = value { |
| 784 | if util::pascal_case().is_match(&name) { |
| 785 | if let Some(inner) = self.react_component_hoc(v) { |
| 786 | self.extract_react_component_node( |
| 787 | &name, |
| 788 | child, |
| 789 | inner, |
| 790 | Extra { |
| 791 | docstring: docstring.clone(), |
| 792 | signature: init_signature.clone(), |
| 793 | is_exported: Some(is_exported), |
| 794 | ..Extra::default() |
| 795 | }, |
| 796 | ); |
| 797 | if inner.is_none() { |
no test coverage detected