TypeScript: an import resolves to a same-named method of an exported object literal instead of the exported function
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
- 領域
- tooling
調査の方向性
src/resolution/import-resolver.ts の getFileExportIndex、279 行目あたりから始めてください。ここでは名前ごとに最初のエクスポートされたノードが優先され、オブジェクトリテラルのメソッド hashDriver::symbolHref が実際のエクスポートを隠します。2 ファイルの nav.ts/walk.ts フィクスチャで再現し(issue に正確な形が示されています)、次に提案されたタイブレークを適用して比較し、__tests__/ui-package.test.ts と import/export/reexport/barrel/commonjs のスイートを CODEGRAPH_KERNEL=0 で実行してください。完了とは、walkTo が nav.ts:6 にリンクし、それらのスイートがグリーンのままであることを意味します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C
- スター
- 73.2k
- フォーク
- 4.7k
- 平均マージ
- 3時間 13分
- マージ済み PR(30日)
- 579
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
colbymchenry/codegraph のほかの issue
-
mcp: a projectPath naming a file inside a project returns isError ("Path is not a directory")対応中かも @maxmilian が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
colbymchenry/codegraph#2982 ·
メンテナーはふだん 1 日以内に返信
-
mcp: a non-object tools/call arguments crashes the handler and is reported as an internal error to retry対応中かも @kjgggggg が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
colbymchenry/codegraph#2981 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
colbymchenry/codegraph#2974 ·
メンテナーはふだん 1 日以内に返信
-
search: FTS special characters are deleted, not separated, so leaf(entry) matches nothing対応中かも @kjgggggg が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
colbymchenry/codegraph#2971 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
colbymchenry/codegraph#2959 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
colbymchenry/codegraph の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
libsdl-org/SDL#16607 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PowerShell/Win32-OpenSSH#2482 · リアクション 1 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OpenMathLib/OpenBLAS#6192 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 2 日以内に返信