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>)
| 785 | /// the declaration skips them; it would take each again for the file). |
| 786 | /// Mirrors TreeSitterExtractor.extractVariable. |
| 787 | pub(super) fn extract_variable(&mut self, node: Node<'t>) -> Option<HashSet<usize>> { |
| 788 | let mut walked: Option<HashSet<usize>> = None; |
| 789 | let is_const = self.is_const_decl(node); |
| 790 | let kind: &'static str = if is_const { "constant" } else { "variable" }; |
| 791 | let docstring = crate::docstring::preceding_docstring(node, self.src); |
| 792 | let is_exported = self.is_exported(node); // `?? false` — always present |
| 793 | |
| 794 | for child in node.named_children(&mut node.walk()) { |
| 795 | if child.kind() != "variable_declarator" { |
| 796 | continue; |
| 797 | } |
| 798 | let Some(name_node) = child.child_by_field_name("name") else { continue }; |
| 799 | let value = child.child_by_field_name("value"); |
| 800 | |
| 801 | // Destructured patterns mint no node — except RTK Query generated |
| 802 | // hooks (`export const { useGetXQuery } = api`). |
| 803 | if matches!(name_node.kind(), "object_pattern" | "array_pattern") { |
| 804 | if name_node.kind() == "object_pattern" |
| 805 | && value.map(|v| v.kind() == "identifier").unwrap_or(false) |
| 806 | { |
| 807 | self.extract_rtk_hook_bindings(name_node, is_exported); |
| 808 | } |
| 809 | // The initializer (and any default in the pattern) still runs: |
| 810 | // walk the declarator as a function body walks it, with the |
| 811 | // enclosing scope on the stack (#2340). Mirrors |
| 812 | // TreeSitterExtractor.extractVariable. |
| 813 | self.visit_function_body(child); |
| 814 | continue; |
| 815 | } |
| 816 | let name = self.text(name_node).to_string(); |
| 817 | |
| 818 | // Arrow/function/generator values extract as functions, named by the declarator. |
| 819 | if let Some(v) = value { |
| 820 | if matches!(v.kind(), "arrow_function" | "function_expression" | "generator_function") { |
| 821 | self.extract_function(v, None); |
| 822 | continue; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | let init_signature = value.map(|v| util::init_signature(self.text(v))); |
| 827 | |
| 828 | // React HOC-wrapped components (#841), PascalCase-gated. |
| 829 | if let Some(v) = value { |
| 830 | if util::pascal_case().is_match(&name) { |
| 831 | if let Some(inner) = self.react_component_hoc(v) { |
| 832 | self.extract_react_component_node( |
| 833 | &name, |
| 834 | child, |
| 835 | inner, |
| 836 | Extra { |
| 837 | docstring: docstring.clone(), |
| 838 | signature: init_signature.clone(), |
| 839 | is_exported: Some(is_exported), |
| 840 | ..Extra::default() |
| 841 | }, |
| 842 | ); |
| 843 | if inner.is_none() { |
| 844 | walked.get_or_insert_with(HashSet::new).insert(v.id()); |
no test coverage detected