TypeScript: an import resolves to a same-named method of an exported object literal instead of the exported function
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- tooling
Hướng nghiên cứu
Bắt đầu trong src/resolution/import-resolver.ts tại getFileExportIndex quanh dòng 279, nơi nút được export đầu tiên theo mỗi tên thắng và phương thức object literal hashDriver::symbolHref che khuất export thật. Tái hiện với fixture hai tệp nav.ts/walk.ts (issue cho thấy hình dạng chính xác), sau đó áp dụng và so sánh tie-break được đề xuất, chạy __tests__/ui-package.test.ts và các bộ test import/export/reexport/barrel/commonjs với CODEGRAPH_KERNEL=0. Hoàn tất nghĩa là walkTo liên kết tới nav.ts:6 và các bộ test đó vẫn xanh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
import { f } from './m' resolves to a method named f inside an exported object literal in m.ts, instead of m.ts's exported function f, when the object comes first in the file.
// nav.ts
export interface Driver { symbolHref(id: string): string; }
export const hashDriver: Driver = {
symbolHref(id) { return '#' + id; }, // line 3
};
let driver: Driver = hashDriver;
export function symbolHref(id: string): string { return driver.symbolHref(id); } // line 6
// walk.ts
import { symbolHref } from './nav';
export function walkTo(id: string) { return symbolHref(id); }
| expected | actual | |
|---|---|---|
walkTo calls |
symbolHref at nav.ts:6 |
symbolHref at nav.ts:3 (hashDriver::symbolHref, resolvedBy: import) |
Reproduced on main at 31ec9082 with CODEGRAPH_KERNEL=0, and on 69af19ac with the native kernel too (Linux/WSL2, Node 22.23.2). The same thing happens in this repo: ui/src/lib/walk.ts calls symbolHref/navigate, and __tests__/ui-package.test.ts calls symbolHref/fileHref/mapHref/flowHref. All of them land on hashNavigation's methods in ui/src/lib/navigation.ts (lines 123–187) rather than the exported functions at lines 240–272.
Cause. The object's method is indexed as function symbolHref, isExported = 1, qualifiedName hashDriver::symbolHref (presumably through the object-literal extraction for an exported const). getFileExportIndex keeps the first exported node per name (import-resolver.ts#L279), so the method shadows the real export.
Possible fix. When two exported nodes share a name, let a top-level declaration replace a member:
const prev = idx.byName.get(n.name);
if (!prev || (prev.qualifiedName !== prev.name && n.qualifiedName === n.name)) idx.byName.set(n.name, n);
With that change walkTo links to nav.ts:6, and the 62 __tests__ files matching import/export/reexport/barrel/store/commonjs/require/default pass (490 tests, CODEGRAPH_KERNEL=0). I haven't run the full suite, and a stricter version might keep members out of byName entirely.
Not fixed by #2754 or #2800: I ran this fixture on both heads and the edge still lands on line 3. I also searched open issues and PRs for object-literal methods and import namesakes, and found nothing else that covers it.
- Ngôn ngữ chính
- C
- Star
- 73.2k
- Fork
- 4.7k
- Merge trung bình
- 3 giờ 39 phút
- Pull request đã merge (30 ngày)
- 528
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của colbymchenry/codegraph
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
colbymchenry/codegraph#3223 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A `../` entry in package.json `workspaces` makes a folder outside the project count as a workspace package, and a call gets linked to the wrong functionCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
colbymchenry/codegraph#3093 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launchĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
colbymchenry/codegraph#3054 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
colbymchenry/codegraph#2974 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Security Vulnerabiliy] Vulnerable bundled `node.exe` detected (Node2Shell - CVE-2026-111497)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
colbymchenry/codegraph#2959 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của colbymchenry/codegraph
Issue tương tự
-
ai-driven-fuzzing bug claude Minor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
linagora/open-bastion#425 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[docs] gravity.md notationsĐang mởquestion
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
follow-up Prio 📌
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
moonbitlang/async#713 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
examples/dnsdoctor: cleanup.sh stops at the first missing piece of a setup.sh that did not finishĐang mởseverity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
luainkernel/lunatik#2263 ·
Maintainer thường phản hồi trong vòng 1 ngày