Repository navigation
Description
Summary
await import('…') inside a nested function (a function declared inside another function) produces no edge in plain .ts/.js. The same statement at the top level of a function resolves fine, which is what makes this easy to miss — a corpus can look fully connected while every cycle-breaking dynamic import is silently dropped.
Distinct from #2153 (that one is jsconfig baseUrl and states outright it is not a dynamic-import() issue) and from #692 (.svelte markup-level).
Reproduction
Four files, one import statement each, identical specifier. graphify 0.9.36 and 0.9.37.
// src/agent/AgentRunner.ts
export const runAgent = () => 1// C_toplevel.ts — import at the top level of an exported function
export async function go() {
const { runAgent } = await import('../agent/AgentRunner');
return runAgent;
}// D_in_try.ts — same, wrapped in try/catch
export async function go() {
try {
const { runAgent } = await import('../agent/AgentRunner');
return runAgent;
} catch { return null; }
}// E_nested_fn.ts — function inside a function
export function outer() {
async function inner() {
const { runAgent } = await import('../agent/AgentRunner');
return runAgent;
}
return inner;
}// F_nested_try.ts — nested + try
export function outer() {
async function inner() {
try {
const { runAgent } = await import('../agent/AgentRunner');
return runAgent;
} catch { return null; }
}
return inner;
}graphify extract . --code-only| file | edge to AgentRunner.ts |
|---|---|
C_toplevel.ts |
✅ imports_from |
D_in_try.ts |
✅ imports_from |
E_nested_fn.ts |
❌ none |
F_nested_try.ts |
❌ none |
Nesting is the only variable. Not the alias (@/… behaves the same), not the specifier depth (../../… behaves the same), not the target file's size, not the presence of static imports in the same file — all four were tested and ruled out separately.
Second, independent gap: affected cannot traverse dynamic edges
DEFAULT_AFFECTED_RELATIONS in graphify/affected.py does not contain dynamic_import. So even the dynamic edges the Svelte/Astro/Vue rescue passes do emit are invisible to graphify affected. Fixing the extractor alone does not restore blast-radius traversal.
Impact, measured
On a 546-file TypeScript app that uses await import() deliberately to break import cycles — so the dynamic imports sit under the hub modules — 31 real edges were missing from graph.json.
Because the loss is concentrated under hubs, it compounds with depth. Against ground truth from an independently written import resolver (730 files, 1,961 edges, 1.7% margin — deliberately not graphify, so the tool is not grading itself):
| depth | truly affected | graphify affected |
recall |
|---|---|---|---|
| 1 | 2 | 2 | 1.00 |
| 2 | 8 | 5 | 0.62 |
| 3 | 30 | 8 | 0.27 |
Precision stayed 1.00 at every depth — graphify under-reports here, it never invents. That is the kindest possible failure mode, and also the reason it goes unnoticed: the answer looks clean, it is just short.
One missing edge under a hub amputated an entire subtree — a single store module pulled ~14 UI components out of the blast radius with it.
Suggested fix
The mechanism already exists in the codebase. extract_svelte / extract_astro / extract_vue each run a regex rescue for exactly this, and extract_vue's docstring names the underlying cause:
"A regex pass then recovers
import('…')dynamic imports the AST does not edge"
Plain .ts/.js never got that pass, presumably because its AST pass works — which it does, for static imports and for un-nested dynamic ones.
Applying the same rescue in extract_js (reusing _emit_rescued_import, _load_tsconfig_aliases, _load_tsconfig_base_url, so aliases resolve identically to static imports) plus adding dynamic_import to DEFAULT_AFFECTED_RELATIONS:
- all four reproduction files above get their edge;
- on the 546-file app: 31 missing edges → 0, recall 0.27 → 1.00 at every depth, precision still 1.00;
- graphify's own suite is unchanged — 6 failed / 3931 passed identically with and without, those 6 being environmental in my setup (missing
ollama, a wheel-build test, anapmmanifest dependency).
Happy to open a PR — a branch with the change plus six tests (relative, multi-level relative, tsconfig-aliased, static-alongside-dynamic, an identifier-boundary guard so fooimport('x') does not match, and one asserting affected can traverse the relation) is ready. Verified to fail without the change: 5 of the 6 are red on v8.
Environment
graphify 0.9.36 (PyPI) and 0.9.37 (v8 @ 09a34ad) · macOS 15 arm64 · Python 3.12
Activity
fix: JS/Kotlin/Swift/SQL extractor correctness batch; bump to 0.9.38 (#…
safishamsi commentedon Aug 9, 2026
Fixed in v0.9.38. A dynamic
await import(...)inside a nested function or at module scope now produces an edge,dynamic_importedges are included inaffected, and calls inside a nested named function are collected too. A dynamic import already captured as a deferred imports_from is not double-counted. Thanks @phudayyy for the fix (PR #2574).fix: JS/Kotlin/Swift/SQL extractor correctness batch; bump to 0.9.38 (G…