(&mut self, node: Node<'t>, name_override: Option<String>)
| 15 | // --- extractFunction -------------------------------------------------------- |
| 16 | |
| 17 | pub(super) fn extract_function(&mut self, node: Node<'t>, name_override: Option<String>) { |
| 18 | let mut name = name_override |
| 19 | .clone() |
| 20 | .unwrap_or_else(|| self.extract_name(node)); |
| 21 | |
| 22 | // Arrow/function-expression values: resolve the name from the parent |
| 23 | // variable_declarator (`export const useAuth = () => {}`). |
| 24 | if name_override.is_none() |
| 25 | && name == "<anonymous>" |
| 26 | && matches!(node.kind(), "arrow_function" | "function_expression") |
| 27 | { |
| 28 | if let Some(parent) = node.parent() { |
| 29 | if parent.kind() == "variable_declarator" { |
| 30 | if let Some(var_name) = parent.child_by_field_name("name") { |
| 31 | name = self.text(var_name).to_string(); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | if name == "<anonymous>" { |
| 37 | // Still walk the body: module wrappers hold named inner functions |
| 38 | // and calls that would otherwise be lost (#528). |
| 39 | if let Some(body) = body_of(node) { |
| 40 | self.visit_function_body(body); |
| 41 | } |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | let extra = Extra { |
| 46 | docstring: crate::docstring::preceding_docstring(node, self.src), |
| 47 | signature: self.signature_of(node), |
| 48 | visibility: self.visibility_of(node), |
| 49 | is_exported: Some(self.is_exported(node)), |
| 50 | is_async: Some(self.is_async(node)), |
| 51 | is_static: self.is_static(node), |
| 52 | ..Extra::default() |
| 53 | }; |
| 54 | let Some(row) = self.create_node("function", &name, node, extra) else { |
| 55 | return; |
| 56 | }; |
| 57 | |
| 58 | self.extract_type_annotations(node, row); |
| 59 | self.extract_decorators_for(node, row); |
| 60 | |
| 61 | self.stack.push(Scope { row, kind: "function", name }); |
| 62 | if let Some(body) = body_of(node) { |
| 63 | self.visit_function_body(body); |
| 64 | } |
| 65 | self.stack.pop(); |
| 66 | } |
| 67 | |
| 68 | // --- reactComponentHoc / extractReactComponentNode (#841) -------------------- |
| 69 |
no test coverage detected