Walk the AST and extract entities
(
&self,
node: &Node,
source: &str,
file_path: &str,
entities: &mut Vec<Entity>,
in_export: bool,
)
| 543 | |
| 544 | /// Walk the AST and extract entities |
| 545 | fn walk_tree( |
| 546 | &self, |
| 547 | node: &Node, |
| 548 | source: &str, |
| 549 | file_path: &str, |
| 550 | entities: &mut Vec<Entity>, |
| 551 | in_export: bool, |
| 552 | ) { |
| 553 | // Check if this node is an export statement |
| 554 | let is_export = node.kind() == "export_statement"; |
| 555 | let child_in_export = in_export || is_export; |
| 556 | |
| 557 | match node.kind() { |
| 558 | "import_statement" | "export_statement" => { |
| 559 | if let Some(module) = node.child_by_field_name("source") { |
| 560 | if let Some(text) = self.node_text(&module, source) { |
| 561 | entities.push( |
| 562 | Entity::new( |
| 563 | text.trim_matches(['\'', '"']), |
| 564 | EntityKind::Import, |
| 565 | file_path, |
| 566 | node.start_position().row as u32 + 1, |
| 567 | node.end_position().row as u32 + 1, |
| 568 | ) |
| 569 | .with_signature(self.node_text(node, source).unwrap_or_default()), |
| 570 | ); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | // Function declarations |
| 576 | "function_declaration" => { |
| 577 | if let Some(entity) = |
| 578 | self.extract_function(node, source, file_path, child_in_export) |
| 579 | { |
| 580 | entities.push(entity); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | // Arrow functions assigned to variables (const foo = () => {}) |
| 585 | "lexical_declaration" | "variable_declaration" => { |
| 586 | entities.extend(self.extract_variable_declarations( |
| 587 | node, |
| 588 | source, |
| 589 | file_path, |
| 590 | child_in_export, |
| 591 | )); |
| 592 | } |
| 593 | |
| 594 | // Class declarations |
| 595 | "class_declaration" => { |
| 596 | if let Some(entity) = self.extract_class(node, source, file_path, child_in_export) { |
| 597 | entities.push(entity); |
| 598 | } |
| 599 | // Also extract methods from the class |
| 600 | self.extract_class_members(node, source, file_path, entities); |
| 601 | } |
| 602 |
no test coverage detected