MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_property

Method extract_property

codegraph-kernel/src/tsjs/extractors.rs:631–697  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

629 // --- extractProperty (#808 property-classified class fields) ---------------------
630
631 pub(super) fn extract_property(&mut self, node: Node<'t>) -> Option<(u32, String)> {
632 let docstring = crate::docstring::preceding_docstring(node, self.src);
633 let visibility = self.visibility_of(node);
634 let is_static = Some(self.is_static(node).unwrap_or(false)); // `?? false` — always present
635
636 let name_node = node
637 .child_by_field_name("name")
638 .or_else(|| node.child_by_field_name("property"))
639 .or_else(|| {
640 (0..node.named_child_count())
641 .filter_map(|i| node.named_child(i))
642 .find(|c| c.kind() == "identifier")
643 })?;
644 let name = self.text(name_node).to_string();
645
646 // TS/JS field definitions carry an explicit `type` field; the generic
647 // scan is for other languages (#808). A `property_signature` (an
648 // interface member, #1638) carries a `type` field and no value, so it
649 // reads the type field too: the generic scan's exclusion list covers
650 // `identifier` but not the `property_identifier` an interface member is
651 // named with, so it would stop on the name and make the signature repeat
652 // it (`counts counts`) instead of naming the type. Mirrors
653 // extractProperty's isTsJsField.
654 let is_ts_js_field = matches!(
655 node.kind(),
656 "public_field_definition" | "field_definition" | "property_signature"
657 );
658 let type_node = if is_ts_js_field {
659 node.child_by_field_name("type")
660 } else {
661 (0..node.named_child_count()).filter_map(|i| node.named_child(i)).find(|c| {
662 !matches!(
663 c.kind(),
664 "modifier"
665 | "modifiers"
666 | "identifier"
667 | "accessor_list"
668 | "accessors"
669 | "equals_value_clause"
670 )
671 })
672 };
673 let type_text = type_node.map(|t| {
674 let raw = self.text(t);
675 raw.strip_prefix(':').unwrap_or(raw).trim_start().to_string()
676 });
677 let signature = match &type_text {
678 Some(t) => format!("{t} {name}"),
679 None => name.clone(),
680 };
681
682 let row = self.create_node(
683 "property",
684 &name,
685 node,
686 Extra { docstring, signature: Some(signature), visibility, is_static, ..Extra::default() },
687 )?;
688 self.extract_decorators_for(node, row);

Callers 1

visit_nodeMethod · 0.45

Calls 9

preceding_docstringFunction · 0.85
mapMethod · 0.80
textMethod · 0.65
visibility_ofMethod · 0.45
is_staticMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected