fix(ingestion): extract TS/JS re-exports, multi-line imports, and computed dynamic imports#194
Merged
Merged
Conversation
…puted dynamic imports
The shared TS/JS import extractor dropped three dependency-edge cases:
- `export ... from "m"` re-export barrels were skipped by an
`import`-prefix guard, so barrel files produced no IMPORTS edge.
- Multi-line named-import clauses (clause wrapped across physical lines
by a formatter) failed the single-line `from` regex and were dropped.
- Dynamic `import(`tpl`)` template-literal specifiers were ignored;
only string-literal `import("...")` matched.
Adds a brace-scoped `joinLogicalLines` (mirrors the Python extractor's
paren-scoped join) that only accumulates lines opening an import/export
named clause, so function/class bodies are never swallowed. Adds
re-export regexes (named -> `named`, `export *` -> `package-wildcard`)
and a static-prefix resolver for template-literal dynamic imports. All
records still flow through the existing IMPORTS edge path keyed on
`source`; no schema change. Shared by .ts/.tsx/.js/.jsx.
Tests: new cases for multi-line imports, named/star re-exports, and
string + template dynamic imports in typescript.test.ts, plus a .js
re-export/dynamic case in javascript.test.ts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes three correctness gaps in the shared TS/JS import extractor (
packages/ingestion/src/providers/ts-shared.ts) that silently dropped real dependency edges. TS/JS is the dominant indexed language, and OpenCodeHub indexes itself with hundreds of re-export barrels and multi-line imports, so this directly improvesimpact/context/ blast-radius accuracy.1. Re-export barrels were dropped
A
!line.startsWith("import")guard meantexport { x } from "m"andexport * from "m"never produced an IMPORTS edge. Added:REEXPORT_NAMED—export { x, y as z } from "m"→namedrecord withimportedNames.REEXPORT_STAR—export * from "m"andexport * as ns from "m"→package-wildcardrecord withisWildcard(+localAliasfor theas nsform).2. Multi-line named imports were dropped
The single-physical-line
from-clause regex failed on formatter-wrapped imports. AddedjoinLogicalLines(), mirroring the Python extractor's paren-scoped joiner but brace-scoped. It only begins accumulating when a line OPENS an import/export named clause (CLAUSE_OPEN), so function/class bodies and object literals are left untouched.3. Template-literal dynamic imports were dropped
DYNAMIC_IMPORTonly matchedimport("..."). AddedDYNAMIC_IMPORT_TEMPLATE+staticTemplatePrefix(): pureimport(`./x`)and static-prefixedimport(`./locales/${l}.json`)→./locales/; fully-interpolated templates dropped (no bogus edge).Why no schema change
ExtractedImport/ImportKindalready carry the needed shapes. Every record flows through the existing IMPORTS edge materialization inpipeline/phases/parse.tskeyed onsource. Output stays source-order deterministic.Scope
Shared by
.ts,.tsx, and.js/.mjs/.cjs/.jsx— all routeextractImports → extractTsImports, verified.Verified
pnpm -F @opencodehub/ingestion build+ fullpnpm --filter '!@opencodehub/docs' -r build— cleanpnpm -F @opencodehub/ingestion test— 567 pass / 0 fail (up from 562; +5 new cases, no regressions)🤖 Surfaced by an automated roadmap-survey workflow; implemented + verified in an isolated worktree.