(&mut self, node: Node<'t>)
| 891 | // --- fn refs (PYTHON_SPEC) ------------------------------------------------------ |
| 892 | |
| 893 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 894 | let (mode, field): (&str, &str) = match node.kind() { |
| 895 | "argument_list" => ("args", ""), |
| 896 | "assignment" => ("rhs", "right"), |
| 897 | "keyword_argument" => ("value", "value"), |
| 898 | "pair" => ("value", "value"), |
| 899 | "list" => ("list", ""), |
| 900 | // `return SomeClass` / `return handler` (#1478) — a single |
| 901 | // returned expression is a direct named child ('list' shape); |
| 902 | // tuple returns sit under expression_list and are not descended |
| 903 | // (mirrors PYTHON_SPEC). |
| 904 | "return_statement" => ("list", ""), |
| 905 | _ => return, |
| 906 | }; |
| 907 | if self.stack.is_empty() { |
| 908 | return; |
| 909 | } |
| 910 | let from = self.top_row(); |
| 911 | |
| 912 | let mut values: Vec<Node> = Vec::new(); |
| 913 | match mode { |
| 914 | "args" | "list" => { |
| 915 | for i in 0..node.named_child_count() { |
| 916 | if let Some(c) = node.named_child(i) { |
| 917 | values.push(c); |
| 918 | } |
| 919 | } |
| 920 | } |
| 921 | "rhs" => { |
| 922 | if let Some(rhs) = node.child_by_field_name(field) { |
| 923 | let lhs_text = node |
| 924 | .child_by_field_name("left") |
| 925 | .map(|l| self.text(l)) |
| 926 | .unwrap_or(""); |
| 927 | let lhs_last = util::lhs_last_name() |
| 928 | .captures(lhs_text) |
| 929 | .and_then(|c| c.get(1)) |
| 930 | .map(|m| m.as_str()); |
| 931 | if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) { |
| 932 | values.push(rhs); |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | _ => { |
| 937 | if let Some(v) = node.child_by_field_name(field) { |
| 938 | values.push(v); |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | for v in values { |
| 944 | let (name, anchor) = match v.kind() { |
| 945 | "identifier" => (self.text(v).to_string(), v), |
| 946 | // Preserve only statically named member chains, as on WASM. |
| 947 | "attribute" => { |
| 948 | let Some(attr) = v.child_by_field_name("attribute") else { continue }; |
| 949 | let name = self.text(v); |
| 950 | if !name.split('.').all(|part| { |
no test coverage detected