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

Method emit_import_binding_refs

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

Source from the content-addressed store, hash-verified

966 }
967
968 fn emit_import_binding_refs(&mut self, node: Node<'t>, from_row: u32) {
969 let clause = (0..node.named_child_count())
970 .filter_map(|i| node.named_child(i))
971 .find(|c| c.kind() == "import_clause");
972 let Some(clause) = clause else { return }; // side-effect import
973
974 let imports_kind = edge_kind_index("imports").unwrap();
975 let push = |w: &mut Self, name_node: Option<Node>| {
976 let Some(n) = name_node else { return };
977 let name = w.text(n).to_string();
978 if name.is_empty() {
979 return;
980 }
981 w.push_ref(from_row, &name, imports_kind, n);
982 };
983
984 for i in 0..clause.named_child_count() {
985 let Some(child) = clause.named_child(i) else { continue };
986 match child.kind() {
987 "identifier" => push(self, Some(child)),
988 "named_imports" => {
989 for j in 0..child.named_child_count() {
990 let Some(spec) = child.named_child(j) else { continue };
991 if spec.kind() != "import_specifier" {
992 continue;
993 }
994 let n = spec
995 .child_by_field_name("alias")
996 .or_else(|| spec.child_by_field_name("name"))
997 .or_else(|| spec.named_child(0));
998 push(self, n);
999 }
1000 }
1001 "namespace_import" => {
1002 let n = (0..child.named_child_count())
1003 .filter_map(|k| child.named_child(k))
1004 .find(|c| c.kind() == "identifier")
1005 .or_else(|| child.named_child(0));
1006 push(self, n);
1007 }
1008 _ => {}
1009 }
1010 }
1011 }
1012
1013 pub(super) fn emit_re_export_refs(&mut self, node: Node<'t>) {
1014 let from_row = self.top_row();

Callers 1

extract_importMethod · 0.80

Calls 4

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
textMethod · 0.45
push_refMethod · 0.45

Tested by

no test coverage detected