Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/codegraph-core/src/domain/graph/builder/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,16 @@ fn collect_imported_names_for_file(
let resolved_path = import_ctx.get_resolved(abs_str, &imp.source);
for name in &imp.names {
let clean_name = name.strip_prefix("* as ").unwrap_or(name).to_string();
// CJS require bindings are included in imported_names so the receiver-edge
// resolver treats them as import artifacts (not locally-defined symbols).
// We use an empty target_file so the import-aware call-target lookup
// (`nodes_by_name_and_file.get(&(name, ""))`) always misses and falls
// through to the same-file shadow node — matching WASM call-resolution
// behaviour where CJS bindings are not in importedNamesMap (#1678).
if imp.cjs_require.unwrap_or(false) {
imported_names.push(ImportedName { name: clean_name, file: String::new() });
continue;
}
let mut target_file = resolved_path.clone();
if import_ctx.is_barrel_file(&resolved_path) {
let mut visited = HashSet::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ pub fn build_import_edges(conn: &Connection, ctx: &ImportEdgeContext) -> Vec<Edg
let abs_str = abs_file.to_str().unwrap_or("");

for imp in &symbols.imports {
// CJS require bindings feed imported_names for receiver-edge resolution
// but must not produce DB import edges (#1678).
if imp.cjs_require.unwrap_or(false) { continue; }
emit_edges_for_import(
&mut edges,
file_node_id,
Expand Down
25 changes: 25 additions & 0 deletions crates/codegraph-core/src/extractors/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,31 @@ fn handle_var_decl(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
// skip destructured const bindings inside function scopes so the
// Rust walk path matches FUNCTION_SCOPE_TYPES behaviour.
extract_destructured_bindings(&name_n, source, start_line(node), end_line(node), &mut symbols.definitions);
// If the RHS is a CJS require() call, also add to imports so the
// receiver-edge resolver treats the names as import artifacts, not
// local definitions — mirroring the WASM cjsRequireBindings fix (#1678).
if value_n.kind() == "call_expression" {
if let Some(fn_node) = value_n.child_by_field_name("function") {
if node_text(&fn_node, source) == "require" {
let args = value_n.child_by_field_name("arguments")
.or_else(|| find_child(&value_n, "arguments"));
if let Some(args) = args {
if let Some(str_arg) = find_child(&args, "string") {
let mod_path = node_text(&str_arg, source)
.replace(&['\'', '"'][..], "");
let names = collect_object_pattern_names(&name_n, source);
if !names.is_empty() {
let mut imp = Import::new(
mod_path, names, start_line(node),
);
imp.cjs_require = Some(true);
symbols.imports.push(imp);
}
}
}
}
}
}
} else if is_const && is_js_literal(&value_n)
&& find_parent_of_types(node, &[
"function_declaration", "arrow_function",
Expand Down
6 changes: 6 additions & 0 deletions crates/codegraph-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ pub struct Import {
pub scala_import: Option<bool>,
#[napi(js_name = "bashSource")]
pub bash_source: Option<bool>,
/// Marks a CJS destructured require binding (`const { X } = require('./m')`).
/// When true, this entry feeds imported_names for receiver-edge resolution
/// but must NOT produce a DB import edge (mirrors WASM cjsRequireBindings, #1678).
#[napi(js_name = "cjsRequire")]
pub cjs_require: Option<bool>,
}

impl Import {
Expand All @@ -176,6 +181,7 @@ impl Import {
swift_import: None,
scala_import: None,
bash_source: None,
cjs_require: None,
}
}
}
Expand Down
129 changes: 0 additions & 129 deletions docs/architecture/decisions/002-dynamic-call-resolution.md

This file was deleted.

Loading
Loading