MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_variable_declarations

Method extract_variable_declarations

atomic-semantic/src/parser.rs:659–694  ·  view source on GitHub ↗

Extract variable declarations (const, let, var) Handles arrow functions assigned to variables

(
        &self,
        node: &Node,
        source: &str,
        file_path: &str,
        exported: bool,
    )

Source from the content-addressed store, hash-verified

657 /// Extract variable declarations (const, let, var)
658 /// Handles arrow functions assigned to variables
659 fn extract_variable_declarations(
660 &self,
661 node: &Node,
662 source: &str,
663 file_path: &str,
664 exported: bool,
665 ) -> Vec<Entity> {
666 let mut entities = Vec::new();
667
668 // Check if it's a const declaration
669 let is_const = node.kind() == "lexical_declaration"
670 && node
671 .child(0)
672 .map(|c| self.node_text(&c, source) == Some("const".to_string()))
673 .unwrap_or(false);
674
675 // Iterate through variable declarators
676 for i in 0..node.child_count() {
677 if let Some(declarator) = node.child(i) {
678 if declarator.kind() == "variable_declarator" {
679 if let Some(entity) = self.extract_variable_declarator(
680 &declarator,
681 node,
682 source,
683 file_path,
684 exported,
685 is_const,
686 ) {
687 entities.push(entity);
688 }
689 }
690 }
691 }
692
693 entities
694 }
695
696 /// Extract a single variable declarator
697 fn extract_variable_declarator(

Callers 1

walk_treeMethod · 0.80

Calls 5

child_countMethod · 0.80
kindMethod · 0.45
node_textMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected