| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…2071) buildImportArtifactNames's local barrel-tracing helper kept only the resolved file and dropped the resolved declared name, asymmetric with buildImportedNamesMap's ESM path. Extract the shared traceBarrelTarget helper in resolve-imports.ts so both paths trace barrel renames identically and can no longer silently diverge. No user-facing behavior change (docs check acknowledged) — internal resolver-internals fix with no new languages, commands, or architecture. Impact: 7 functions changed, 15 affected
Greptile SummaryThis PR centralizes barrel-target tracing and preserves the underlying declared name for CommonJS bindings passing through renamed barrel exports.
Confidence Score: 5/5The PR appears safe to merge, with no concrete behavioral, build, or security regression identified. The shared helper preserves prior ESM semantics, correctly carries renamed CJS declarations, and the richer map values remain unobserved by the sole consumer, which only checks key presence. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
Import["ESM import or CJS require binding"] --> Resolve["Resolve imported path"]
Resolve --> Trace["traceBarrelTarget(path, name)"]
Trace --> Check{"Barrel file?"}
Check -->|No| Original["Return original file and name"]
Check -->|Yes| Barrel["resolveBarrelExportCached"]
Barrel --> Found{"Export resolved?"}
Found -->|Yes| Target["Return declaring file and translated name"]
Found -->|No| Original
Target --> Map["Store import-artifact resolution"]
Original --> Map
Map --> Classify["resolveReceiverEdge checks key presence"]
Reviews (1): Last reviewed commit: "fix: preserve barrel-renamed declared na..." | Re-trigger Greptile |
Sorry, something went wrong.
Codegraph Impact Analysis7 functions changed → 15 callers affected across 3 files
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
buildImportArtifactNames's local barrel-tracing helper (traceBarrel) resolved through barrel chains via resolveBarrelExportCached but kept only resolved.file, discarding resolved.name — the declared name after a barrel-rename translation (export { realName as friendlyName } from './underlying'). This was asymmetric with the ESM import path's own traceBarrel in buildImportedNamesMap (same file), which correctly threads .name through.
No consumer currently reads the dropped value — resolveReceiverEdge, the sole consumer of importArtifactNames, only calls .has() for import-artifact classification, never .get() — so this was latent, not an observed bug. But if a future consumer needs the correct declared name (mirroring how the ESM path already works), the CJS-through-a-renamed-barrel case would have silently carried the wrong name with no test coverage catching it.
Fix
Extracted a single shared traceBarrelTarget(ctx, resolvedPath, name) helper into resolve-imports.ts — the module that already owns isBarrelFile/resolveBarrelExportCached/BarrelExportResolution. Both buildImportedNamesMap (ESM) and buildImportArtifactNames (CJS require()) now call this one implementation instead of maintaining separate private copies, so they can no longer silently diverge the way they did here.
buildImportArtifactNames's return type widened from Map<string,string> (name -> file) to ReadonlyMap<string, BarrelExportResolution> (name -> {file, name}), matching the fix sketch from the issue. resolveReceiverEdge's importedNames parameter type widened to ReadonlyMap<string, unknown> since it only ever checks .has() and is fed either the plain ESM map or the richer artifact map.
No native-engine changes — the issue confirms there's no native equivalent of buildImportArtifactNames to diverge from.
Verification
Filed #2295 for a related but out-of-scope cleanup: three other inline barrel-trace call sites in build-edges.ts duplicate the same fallback pattern but are already correct, so consolidating them onto traceBarrelTarget too was left for a follow-up.
Closes #2071