Skip to content

fix(svelte): stamp dynamic-import stub source_file to target, not importer#2

Closed
jippi wants to merge 1 commit into
v7from
fix/svelte-stub-node-source-file
Closed

fix(svelte): stamp dynamic-import stub source_file to target, not importer#2
jippi wants to merge 1 commit into
v7from
fix/svelte-stub-node-source-file

Conversation

@jippi

@jippi jippi commented May 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

…orter (Graphify-Labs#712)

When extract_svelte()'s regex pass for `import('...')` resolved a target
path (relative or via tsconfig alias) and created a stub node for it,
the stub's source_file was stamped to str(path) — the IMPORTER's path,
not the target's path.

build_from_json does last-write-wins on node attributes (G.add_node
overwrites). When the target file is later extracted by _extract_generic
on its own, both nodes share the same id (_make_id(str(target))) and
merge. Whether the stub's wrong source_file or the real correct one wins
depends purely on file-iteration order — non-deterministic.

Effect: downstream tools that read source_file off file nodes (display,
"where is X defined", blast-radius queries, community summaries) see the
file as living inside whichever component first imported it. On a real
1,873-file SvelteKit codebase, 16 .svelte file nodes were corrupted this
way — every dynamically-imported component sampled.

The fix threads the resolved target path through to source_file:
  - relative imports use str(resolved)
  - alias imports use str(resolved_alias)
  - bare/scoped externals leave source_file empty (we genuinely don't
    know where node_modules live, and stamping the importer would lie)

The stub edge's source_file is unchanged — that legitimately is the
importer (where the import statement lives).

7 new tests in tests/test_svelte_dynamic_import_stub.py:
  - relative import stub points to target
  - relative import stub does NOT carry importer's path
  - alias import resolves and points to target
  - two importers of same target produce consistent source_file
  - stub doesn't clobber target's own extraction (merge-order safety)
  - bare-module stub doesn't claim to be importer
  - dynamic_import edge source_file remains the importer (no over-correction)

6 of 7 fail against unpatched v7 (proving they're real regression
guards); the 7th is the over-correction check which intentionally
documents what should NOT change.
@jippi jippi closed this May 4, 2026
@jippi jippi changed the title fix(svelte): stamp dynamic-import stub source_file to target, not importer (#712) fix(svelte): stamp dynamic-import stub source_file to target, not importer May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant