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

Method emit_import_binding_refs

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

Source from the content-addressed store, hash-verified

1683 }
1684
1685 fn emit_import_binding_refs(&mut self, node: Node<'t>, from_row: u32) {
1686 let clause = (0..node.named_child_count())
1687 .filter_map(|i| node.named_child(i))
1688 .find(|c| c.kind() == "import_clause");
1689 let Some(clause) = clause else { return }; // side-effect import
1690
1691 let imports_kind = edge_kind_index("imports").unwrap();
1692 let push = |w: &mut Self, name_node: Option<Node>| {
1693 let Some(n) = name_node else { return };
1694 let name = w.text(n).to_string();
1695 if name.is_empty() {
1696 return;
1697 }
1698 w.push_ref(from_row, &name, imports_kind, n);
1699 };
1700
1701 for i in 0..clause.named_child_count() {
1702 let Some(child) = clause.named_child(i) else { continue };
1703 match child.kind() {
1704 "identifier" => push(self, Some(child)),
1705 "named_imports" => {
1706 for j in 0..child.named_child_count() {
1707 let Some(spec) = child.named_child(j) else { continue };
1708 if spec.kind() != "import_specifier" {
1709 continue;
1710 }
1711 let n = spec
1712 .child_by_field_name("alias")
1713 .or_else(|| spec.child_by_field_name("name"))
1714 .or_else(|| spec.named_child(0));
1715 push(self, n);
1716 }
1717 }
1718 "namespace_import" => {
1719 let n = (0..child.named_child_count())
1720 .filter_map(|k| child.named_child(k))
1721 .find(|c| c.kind() == "identifier")
1722 .or_else(|| child.named_child(0));
1723 push(self, n);
1724 }
1725 _ => {}
1726 }
1727 }
1728 }
1729
1730 pub(super) fn emit_re_export_refs(&mut self, node: Node<'t>) {
1731 let from_row = self.top_row();

Callers 1

extract_importMethod · 0.80

Calls 5

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

Tested by

no test coverage detected