Extract a single variable declarator
(
&self,
declarator: &Node,
parent: &Node,
source: &str,
file_path: &str,
exported: bool,
is_const: bool,
)
| 740 | |
| 741 | /// Extract a single variable declarator |
| 742 | fn extract_variable_declarator( |
| 743 | &self, |
| 744 | declarator: &Node, |
| 745 | parent: &Node, |
| 746 | source: &str, |
| 747 | file_path: &str, |
| 748 | exported: bool, |
| 749 | is_const: bool, |
| 750 | ) -> Option<Entity> { |
| 751 | let name_node = declarator.child_by_field_name("name")?; |
| 752 | let name = self.node_text(&name_node, source)?; |
| 753 | |
| 754 | // Check if the value is an arrow function or function expression |
| 755 | let value_node = declarator.child_by_field_name("value"); |
| 756 | let (kind, signature) = if let Some(value) = value_node { |
| 757 | match value.kind() { |
| 758 | "arrow_function" | "function" | "function_expression" => { |
| 759 | let sig = self.build_arrow_function_signature(&name, &value, source); |
| 760 | (EntityKind::Function, Some(sig)) |
| 761 | } |
| 762 | _ => { |
| 763 | if is_const { |
| 764 | let sig = self.build_const_signature(declarator, source); |
| 765 | (EntityKind::Const, Some(sig)) |
| 766 | } else { |
| 767 | (EntityKind::Variable, None) |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | } else if is_const { |
| 772 | (EntityKind::Const, None) |
| 773 | } else { |
| 774 | (EntityKind::Variable, None) |
| 775 | }; |
| 776 | |
| 777 | let mut entity = Entity::new( |
| 778 | name, |
| 779 | kind, |
| 780 | file_path, |
| 781 | parent.start_position().row as u32 + 1, |
| 782 | parent.end_position().row as u32 + 1, |
| 783 | ) |
| 784 | .with_column(parent.start_position().column as u32) |
| 785 | .with_exported(exported); |
| 786 | |
| 787 | if let Some(sig) = signature { |
| 788 | entity = entity.with_signature(sig); |
| 789 | } |
| 790 | |
| 791 | Some(entity) |
| 792 | } |
| 793 | |
| 794 | /// Extract a class declaration |
| 795 | fn extract_class( |
no test coverage detected