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

Method extract_variable_declarator

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

Extract a single variable declarator

(
        &self,
        declarator: &Node,
        parent: &Node,
        source: &str,
        file_path: &str,
        exported: bool,
        is_const: bool,
    )

Source from the content-addressed store, hash-verified

695
696 /// Extract a single variable declarator
697 fn extract_variable_declarator(
698 &self,
699 declarator: &Node,
700 parent: &Node,
701 source: &str,
702 file_path: &str,
703 exported: bool,
704 is_const: bool,
705 ) -> Option<Entity> {
706 let name_node = declarator.child_by_field_name("name")?;
707 let name = self.node_text(&name_node, source)?;
708
709 // Check if the value is an arrow function or function expression
710 let value_node = declarator.child_by_field_name("value");
711 let (kind, signature) = if let Some(value) = value_node {
712 match value.kind() {
713 "arrow_function" | "function" | "function_expression" => {
714 let sig = self.build_arrow_function_signature(&name, &value, source);
715 (EntityKind::Function, Some(sig))
716 }
717 _ => {
718 if is_const {
719 let sig = self.build_const_signature(declarator, source);
720 (EntityKind::Const, Some(sig))
721 } else {
722 (EntityKind::Variable, None)
723 }
724 }
725 }
726 } else if is_const {
727 (EntityKind::Const, None)
728 } else {
729 (EntityKind::Variable, None)
730 };
731
732 let mut entity = Entity::new(
733 name,
734 kind,
735 file_path,
736 parent.start_position().row as u32 + 1,
737 parent.end_position().row as u32 + 1,
738 )
739 .with_column(parent.start_position().column as u32)
740 .with_exported(exported);
741
742 if let Some(sig) = signature {
743 entity = entity.with_signature(sig);
744 }
745
746 Some(entity)
747 }
748
749 /// Extract a class declaration
750 fn extract_class(

Callers 1

Calls 7

build_const_signatureMethod · 0.80
with_exportedMethod · 0.80
with_columnMethod · 0.80
with_signatureMethod · 0.80
node_textMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected