extractCall — the rust paths of the generic else-branch (4312+).
(&mut self, node: Node<'t>)
| 774 | |
| 775 | /// extractCall — the rust paths of the generic else-branch (4312+). |
| 776 | fn extract_call(&mut self, node: Node<'t>) { |
| 777 | if self.stack.is_empty() { |
| 778 | return; |
| 779 | } |
| 780 | let func = node |
| 781 | .child_by_field_name("function") |
| 782 | .or_else(|| node.named_child(0)); |
| 783 | let mut callee_name = String::new(); |
| 784 | |
| 785 | if let Some(func) = func { |
| 786 | if func.kind() == "field_expression" { |
| 787 | let property = func |
| 788 | .child_by_field_name("property") |
| 789 | .or_else(|| func.child_by_field_name("field")) |
| 790 | .or_else(|| func.named_child(1)); |
| 791 | if let Some(property) = property { |
| 792 | let method_name = self.text(property); |
| 793 | let receiver = func |
| 794 | .child_by_field_name("object") |
| 795 | .or_else(|| func.child_by_field_name("operand")) |
| 796 | .or_else(|| func.child_by_field_name("argument")) |
| 797 | .or_else(|| func.named_child(0)); |
| 798 | if let Some(r) = receiver { |
| 799 | if is_literal_receiver(r.kind()) { |
| 800 | return; // emit NOTHING (#1230) |
| 801 | } |
| 802 | } |
| 803 | if let Some(r) = receiver { |
| 804 | match r.kind() { |
| 805 | // rust `self` is node kind `self`, NOT `identifier` — |
| 806 | // it dodges this branch and falls to the bare-name |
| 807 | // fallthrough (same net effect as SKIP_RECEIVERS). |
| 808 | "identifier" | "simple_identifier" | "field_identifier" => { |
| 809 | let receiver_name = self.text(r); |
| 810 | if !matches!(receiver_name, "self" | "this" | "cls" | "super") { |
| 811 | callee_name = format!("{receiver_name}.{method_name}"); |
| 812 | } else { |
| 813 | callee_name = method_name.to_string(); |
| 814 | } |
| 815 | } |
| 816 | "call_expression" => { |
| 817 | // Chained-call re-encode: ONLY an associated- |
| 818 | // function chain (`Foo::new().bar()`, inner |
| 819 | // callee a scoped_identifier). Instance chains |
| 820 | // keep the bare method name. |
| 821 | let inner_fn = r.child_by_field_name("function"); |
| 822 | let reencode = |
| 823 | inner_fn.map(|f| f.kind() == "scoped_identifier").unwrap_or(false); |
| 824 | if reencode { |
| 825 | let inner: String = self |
| 826 | .text(inner_fn.unwrap()) |
| 827 | .replace("->", ".") |
| 828 | .chars() |
| 829 | .filter(|c| !c.is_whitespace()) |
| 830 | .collect(); |
| 831 | callee_name = format!("{inner}().{method_name}"); |
| 832 | } else { |
| 833 | callee_name = method_name.to_string(); |
no test coverage detected