Walk the AST and extract entities
(
&self,
node: &Node,
source: &str,
file_path: &str,
entities: &mut Vec<Entity>,
in_export: bool,
)
| 571 | |
| 572 | /// Walk the AST and extract entities |
| 573 | fn walk_tree( |
| 574 | &self, |
| 575 | node: &Node, |
| 576 | source: &str, |
| 577 | file_path: &str, |
| 578 | entities: &mut Vec<Entity>, |
| 579 | in_export: bool, |
| 580 | ) { |
| 581 | // Check if this node is an export statement |
| 582 | let is_export = node.kind() == "export_statement"; |
| 583 | let child_in_export = in_export || is_export; |
| 584 | |
| 585 | match node.kind() { |
| 586 | "import_statement" | "export_statement" => { |
| 587 | if let Some(module) = node.child_by_field_name("source") { |
| 588 | if let Some(text) = self.node_text(&module, source) { |
| 589 | entities.push( |
| 590 | Entity::new( |
| 591 | text.trim_matches(['\'', '"']), |
| 592 | EntityKind::Import, |
| 593 | file_path, |
| 594 | node.start_position().row as u32 + 1, |
| 595 | node.end_position().row as u32 + 1, |
| 596 | ) |
| 597 | .with_signature(self.node_text(node, source).unwrap_or_default()), |
| 598 | ); |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | // Function declarations |
| 604 | "function_declaration" => { |
| 605 | if let Some(entity) = |
| 606 | self.extract_function(node, source, file_path, child_in_export) |
| 607 | { |
| 608 | entities.push(entity); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // Arrow functions assigned to variables (const foo = () => {}) |
| 613 | "lexical_declaration" | "variable_declaration" => { |
| 614 | entities.extend(self.extract_variable_declarations( |
| 615 | node, |
| 616 | source, |
| 617 | file_path, |
| 618 | child_in_export, |
| 619 | )); |
| 620 | } |
| 621 | |
| 622 | // Class declarations |
| 623 | "class_declaration" => { |
| 624 | if let Some(entity) = self.extract_class(node, source, file_path, child_in_export) { |
| 625 | entities.push(entity); |
| 626 | } |
| 627 | // Also extract methods from the class |
| 628 | self.extract_class_members(node, source, file_path, entities); |
| 629 | } |
| 630 |
no test coverage detected