| 728 | } |
| 729 | |
| 730 | fn names(node: Node<'_>, source: &str) -> Vec<String> { |
| 731 | if matches!(node.kind(), "import_statement" | "import_from_statement") { |
| 732 | let mut cursor = node.walk(); |
| 733 | return node |
| 734 | .children_by_field_name("name", &mut cursor) |
| 735 | .map(|name| { |
| 736 | name.child_by_field_name("alias") |
| 737 | .map(|alias| text(alias, source).to_owned()) |
| 738 | .unwrap_or_else(|| { |
| 739 | text(name, source) |
| 740 | .split('.') |
| 741 | .next() |
| 742 | .unwrap_or_default() |
| 743 | .into() |
| 744 | }) |
| 745 | }) |
| 746 | .collect(); |
| 747 | } |
| 748 | let mut cursor = node.walk(); |
| 749 | let mut bindings: Vec<_> = node.children_by_field_name("name", &mut cursor).collect(); |
| 750 | if bindings.is_empty() { |
| 751 | bindings.extend( |
| 752 | node.child_by_field_name("left") |
| 753 | .or_else(|| node.child_by_field_name("pattern")), |
| 754 | ); |
| 755 | } |
| 756 | if !bindings.is_empty() { |
| 757 | let mut result = Vec::new(); |
| 758 | while let Some(binding) = bindings.pop() { |
| 759 | match binding.kind() { |
| 760 | "tuple_pattern" | "list_pattern" | "pattern_list" | "tuple" | "list" |
| 761 | | "array_pattern" | "object_pattern" => bindings.extend(named(binding)), |
| 762 | "pair_pattern" => bindings.extend(binding.child_by_field_name("value")), |
| 763 | "assignment_pattern" | "object_assignment_pattern" => { |
| 764 | bindings.extend(binding.child_by_field_name("left")) |
| 765 | } |
| 766 | "rest_pattern" => bindings.extend(named(binding)), |
| 767 | _ => result.push(text(binding, source).into()), |
| 768 | } |
| 769 | } |
| 770 | return result; |
| 771 | } |
| 772 | if let Some(function) = |
| 773 | declarator(node).and_then(|function| function.child_by_field_name("declarator")) |
| 774 | { |
| 775 | return vec![text(function, source).into()]; |
| 776 | } |
| 777 | if matches!(node.kind(), "declaration" | "field_declaration") { |
| 778 | let mut cursor = node.walk(); |
| 779 | return node |
| 780 | .children_by_field_name("declarator", &mut cursor) |
| 781 | .map(|declaration| { |
| 782 | let declaration = declaration |
| 783 | .child_by_field_name("declarator") |
| 784 | .unwrap_or(declaration); |
| 785 | text(declaration, source).to_owned() |
| 786 | }) |
| 787 | .collect(); |