Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(ingest): don't bind a default import to a member named default

KageBinaryeab107569581
diff --git a/core-ingestion/src/__tests__/resolveEdges.test.ts b/core-ingestion/src/__tests__/resolveEdges.test.ts
index 38e3fd8c..9c666b96 100644
--- a/core-ingestion/src/__tests__/resolveEdges.test.ts
+++ b/core-ingestion/src/__tests__/resolveEdges.test.ts
@@ -616,6 +616,25 @@ describe('resolveEdges', () => {
});
});
+ it('does not bind a default import to a provider member named "default"', () => {
+ // `imported` is the sentinel 'default' for `import run from "./m"`, not an
+ // export name. Without the guard, the renamed-import fallback matches the
+ // *method* `M.default` and emits a confident edge to the wrong member.
+ const provider = parseFile(
+ '/repo/m.ts',
+ 'export class M { default() { return 1; } }\nexport default new M();\n',
+ )!;
+ const consumer = parseFile(
+ '/repo/n.ts',
+ 'import run from "./m";\nexport function go() { return run(); }\n',
+ )!;
+
+ const resolved = resolveEdges([consumer, provider]);
+ expect(
+ resolved.filter((e) => e.srcName === 'go' && e.dstQualifiedKey === 'M.default'),
+ ).toEqual([]);
+ });
+
it('uses caller-supplied parse results instead of re-parsing', () => {
// The CLI parses prescan sources on its worker pool and hands the results
// in, so the index costs no main-thread parsing. Proven by supplying a
diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.ts
index 5b8e5c38..94a0ea99 100644
--- a/core-ingestion/src/index.ts
+++ b/core-ingestion/src/index.ts
@@ -3989,8 +3989,13 @@ export function resolveEdges(
))];
const publicMatches: Array<{ fp: string; local: string }> = [];
for (const fp of providerFiles.length === 1 ? providerFiles : []) {
+ // `imported` is the literal sentinel 'default' for a default import, never a
+ // real export name, so a provider member that happens to be *called* `default`
+ // (a method, getter, or static) must not satisfy the fallback.
const local = filePublicNames.get(fp)?.get(binding.imported)
- ?? (fileHasSymbol.get(fp)?.has(binding.imported) ? binding.imported : undefined);
+ ?? (binding.imported !== 'default' && fileHasSymbol.get(fp)?.has(binding.imported)
+ ? binding.imported
+ : undefined);
if (local && fileHasSymbol.get(fp)?.has(local)) publicMatches.push({ fp, local });
}
if (publicMatches.length === 1) {