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
7 changes: 6 additions & 1 deletion crates/codegraph-core/src/extractors/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,12 @@ fn walk_ast_nodes_depth(node: &Node, source: &[u8], ast_nodes: &mut Vec<AstNode>
text,
receiver: None,
});
// Don't recurse
// Recurse into children to capture nested calls (e.g. await fetch(url))
for i in 0..node.child_count() {
if let Some(child) = node.child(i) {
walk_ast_nodes_depth(&child, source, ast_nodes, depth + 1);
}
}
return;
}
"string" | "template_string" => {
Expand Down
21 changes: 21 additions & 0 deletions tests/engines/ast-parity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface NativeResult {
let native: NativeAddon | null = null;
/** Whether the installed native binary supports call AST nodes. */
let nativeSupportsCallAst = false;
/** Whether the installed native binary recurses into await children (fix for under-counted calls). */
let nativeHasAwaitCallFix = false;

function nativeExtract(code: string, filePath: string): NativeResult {
if (!native) throw new Error('nativeExtract called with native === null');
Expand Down Expand Up @@ -111,6 +113,21 @@ describe('AST node parity (native vs WASM)', () => {
const astNodes = probe.astNodes || [];
nativeSupportsCallAst = astNodes.some((n: AstNodeLike) => n.kind === 'call');
}

// Detect whether this binary recurses into await_expression children.
// Fixed in walk_ast_nodes_depth — older binaries miss calls inside await.
const awaitProbe = native.parseFile(
'/probe-await.js',
'async function f() { await fetch(x); }',
false,
true,
) as NativeResult | null;
if (awaitProbe) {
const astNodes = awaitProbe.astNodes || [];
nativeHasAwaitCallFix = astNodes.some(
(n: AstNodeLike) => n.kind === 'call' && n.name === 'fetch',
);
}
});

it.skipIf(!isNativeAvailable())('JS: native astNodes kinds are valid and well-formed', () => {
Expand Down Expand Up @@ -206,6 +223,10 @@ describe('AST node parity (native vs WASM)', () => {

it.skipIf(!isNativeAvailable())('JS: native calls match legacy calls field count', () => {
if (!nativeSupportsCallAst) return; // runtime guard — set by beforeAll
// walk_ast_nodes_depth didn't recurse into await_expression children,
// so calls inside `await expr()` were missed. Fixed in Rust source —
// skip until the native binary is republished with the fix.
if (!nativeHasAwaitCallFix) return;

const nativeResult = nativeExtract(JS_SNIPPET, '/test/sample.js');
const astNodes = nativeResult.astNodes || [];
Expand Down
Loading