(&mut self, node: Node<'t>)
| 684 | // --- function-as-value capture (#756) — LUA_SPEC ---------------------- |
| 685 | |
| 686 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 687 | // LUA_SPEC dispatch: arguments → args; assignment_statement → rhs |
| 688 | // (no field — last named child; param-storage skip via namedChild(0)); |
| 689 | // field → value (field 'value', last-named-child fallback). |
| 690 | let mode: &str = match node.kind() { |
| 691 | "arguments" => "args", |
| 692 | "assignment_statement" => "rhs", |
| 693 | "field" => "value", |
| 694 | _ => return, |
| 695 | }; |
| 696 | if self.stack.is_empty() { |
| 697 | return; |
| 698 | } |
| 699 | let from = self.top_row(); |
| 700 | |
| 701 | let mut values: Vec<Node<'t>> = Vec::new(); |
| 702 | match mode { |
| 703 | "args" => { |
| 704 | let mut cursor = node.walk(); |
| 705 | for c in node.named_children(&mut cursor) { |
| 706 | values.push(c); |
| 707 | } |
| 708 | } |
| 709 | "rhs" => { |
| 710 | // No `field` in the rule → RHS = LAST named child (the |
| 711 | // expression_list). Param-storage skip: lhs = |
| 712 | // left/lhs/target field ?? namedChild(0) when ≥2 children; |
| 713 | // its trailing identifier vs the whole RHS text. |
| 714 | let count = node.named_child_count(); |
| 715 | let rhs = if count > 0 { node.named_child(count - 1) } else { None }; |
| 716 | if let Some(rhs) = rhs { |
| 717 | let lhs = node |
| 718 | .child_by_field_name("left") |
| 719 | .or_else(|| node.child_by_field_name("lhs")) |
| 720 | .or_else(|| node.child_by_field_name("target")) |
| 721 | .or_else(|| if count >= 2 { node.named_child(0) } else { None }); |
| 722 | let lhs_text = lhs.map(|l| self.text(l)).unwrap_or(""); |
| 723 | let lhs_last = util::lhs_last_name() |
| 724 | .captures(lhs_text) |
| 725 | .and_then(|c| c.get(1)) |
| 726 | .map(|m| m.as_str()); |
| 727 | if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) { |
| 728 | values.push(rhs); |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | _ => { |
| 733 | // value — the `value` field (keyed AND positional table |
| 734 | // fields carry it), falling back to the last named child. |
| 735 | let v = node.child_by_field_name("value").or_else(|| { |
| 736 | let count = node.named_child_count(); |
| 737 | if count > 0 { node.named_child(count - 1) } else { None } |
| 738 | }); |
| 739 | if let Some(v) = v { |
| 740 | values.push(v); |
| 741 | } |
| 742 | } |
| 743 | } |
no test coverage detected