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

Method emit_import_binding_refs

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

Source from the content-addressed store, hash-verified

1701 }
1702
1703 fn emit_import_binding_refs(&mut self, node: Node<'t>, from_row: u32) {
1704 let clause = (0..node.named_child_count())
1705 .filter_map(|i| node.named_child(i))
1706 .find(|c| c.kind() == "import_clause");
1707 let Some(clause) = clause else { return }; // side-effect import
1708
1709 let imports_kind = edge_kind_index("imports").unwrap();
1710 let push = |w: &mut Self, name_node: Option<Node>| {
1711 let Some(n) = name_node else { return };
1712 let name = w.text(n).to_string();
1713 if name.is_empty() {
1714 return;
1715 }
1716 w.push_ref(from_row, &name, imports_kind, n);
1717 };
1718
1719 for child in clause.named_children(&mut clause.walk()) {
1720 match child.kind() {
1721 "identifier" => push(self, Some(child)),
1722 "named_imports" => {
1723 for spec in child.named_children(&mut child.walk()) {
1724 if spec.kind() != "import_specifier" {
1725 continue;
1726 }
1727 let n = spec
1728 .child_by_field_name("alias")
1729 .or_else(|| spec.child_by_field_name("name"))
1730 .or_else(|| spec.named_child(0));
1731 push(self, n);
1732 }
1733 }
1734 "namespace_import" => {
1735 let n = (0..child.named_child_count())
1736 .filter_map(|k| child.named_child(k))
1737 .find(|c| c.kind() == "identifier")
1738 .or_else(|| child.named_child(0));
1739 push(self, n);
1740 }
1741 _ => {}
1742 }
1743 }
1744 }
1745
1746 pub(super) fn emit_re_export_refs(&mut self, node: Node<'t>) {
1747 let from_row = self.top_row();

Callers 1

extract_importMethod · 0.80

Calls 6

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
pushFunction · 0.50
push_refMethod · 0.45
walkMethod · 0.45

Tested by

no test coverage detected