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

Method extract_variable_declarator

atomic-semantic/src/parser.rs:714–764  ·  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

712
713 /// Extract a single variable declarator
714 fn extract_variable_declarator(
715 &self,
716 declarator: &Node,
717 parent: &Node,
718 source: &str,
719 file_path: &str,
720 exported: bool,
721 is_const: bool,
722 ) -> Option<Entity> {
723 let name_node = declarator.child_by_field_name("name")?;
724 let name = self.node_text(&name_node, source)?;
725
726 // Check if the value is an arrow function or function expression
727 let value_node = declarator.child_by_field_name("value");
728 let (kind, signature) = if let Some(value) = value_node {
729 match value.kind() {
730 "arrow_function" | "function" | "function_expression" => {
731 let sig = self.build_arrow_function_signature(&name, &value, source);
732 (EntityKind::Function, Some(sig))
733 }
734 _ => {
735 if is_const {
736 let sig = self.build_const_signature(declarator, source);
737 (EntityKind::Const, Some(sig))
738 } else {
739 (EntityKind::Variable, None)
740 }
741 }
742 }
743 } else if is_const {
744 (EntityKind::Const, None)
745 } else {
746 (EntityKind::Variable, None)
747 };
748
749 let mut entity = Entity::new(
750 name,
751 kind,
752 file_path,
753 parent.start_position().row as u32 + 1,
754 parent.end_position().row as u32 + 1,
755 )
756 .with_column(parent.start_position().column as u32)
757 .with_exported(exported);
758
759 if let Some(sig) = signature {
760 entity = entity.with_signature(sig);
761 }
762
763 Some(entity)
764 }
765
766 /// Extract a class declaration
767 fn extract_class(

Callers 1

Calls 7

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

Tested by

no test coverage detected