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

Method emit_import_binding_refs

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

Source from the content-addressed store, hash-verified

2088 }
2089
2090 fn emit_import_binding_refs(&mut self, node: Node<'t>, from_row: u32) {
2091 let clause = (0..node.named_child_count())
2092 .filter_map(|i| node.named_child(i))
2093 .find(|c| c.kind() == "import_clause");
2094 let Some(clause) = clause else { return }; // side-effect import
2095
2096 let imports_kind = edge_kind_index("imports").unwrap();
2097 let push = |w: &mut Self, name_node: Option<Node>| {
2098 let Some(n) = name_node else { return };
2099 let name = w.text(n).to_string();
2100 if name.is_empty() {
2101 return;
2102 }
2103 w.push_ref(from_row, &name, imports_kind, n);
2104 };
2105
2106 for child in clause.named_children(&mut clause.walk()) {
2107 match child.kind() {
2108 "identifier" => push(self, Some(child)),
2109 "named_imports" => {
2110 for spec in child.named_children(&mut child.walk()) {
2111 if spec.kind() != "import_specifier" {
2112 continue;
2113 }
2114 let n = spec
2115 .child_by_field_name("alias")
2116 .or_else(|| spec.child_by_field_name("name"))
2117 .or_else(|| spec.named_child(0));
2118 push(self, n);
2119 }
2120 }
2121 "namespace_import" => {
2122 let n = (0..child.named_child_count())
2123 .filter_map(|k| child.named_child(k))
2124 .find(|c| c.kind() == "identifier")
2125 .or_else(|| child.named_child(0));
2126 push(self, n);
2127 }
2128 _ => {}
2129 }
2130 }
2131 }
2132
2133 pub(super) fn emit_re_export_refs(&mut self, node: Node<'t>) {
2134 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