JS/TS: an `export default NAME` line inside a template literal is taken as the module's default export
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 64/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- tooling
調査の方向性
Start by reading statedDefaultExport in src/resolution/import-resolver.ts (lines 210-244) and the EXPORT_DEFAULT_HEAD scan loop that breaks on the first statement naming a node. Check what the extractor exposes for real export_statement positions so the loop can skip matches inside template or string literals rather than relying on a masker. Reproduce with the gen.ts/use.ts pair under CODEGRAPH_KERNEL=0, then confirm via the resolution tests that use resolves to Main and not App.
索引モデルが issue の本文から書いたものです。
説明
The default-export reader takes an export default NAME line inside a template literal as the module's default export when NAME is a node of the file. The real export default statement later in the file is then ignored.
// gen.ts
export function App() { return 1; }
export function Main() { return 2; }
export const template = `
export default App
`;
export default Main;
// use.ts
import X from './gen';
export function use() { return X(); }
edge on main |
expected | |
|---|---|---|
use → |
App (gen.ts:1, resolvedBy: import) ✗ |
Main (gen.ts:2) |
statedDefaultExport (import-resolver.ts#L210-L244) scans comment-stripped source but deliberately doesn't mask strings. Its docstring explains why: a masker thrown out of step by nested templates blanked real statements. It relies on "a statement must name a node of the file instead — one a template only writes as text names none — and of several statements, one that does wins". That fails when the template's text names a real node, as in code generators, scaffolding scripts and docs/test helpers that build module source in template strings. The loop takes the first statement that names a node and breaks, so the template wins whenever it comes first.
Reproduced on main at 72f398af with CODEGRAPH_KERNEL=0. Linux/WSL2, Node 22.23.2.
Possible direction (not verified). Skip an EXPORT_DEFAULT_HEAD match that sits inside a template or string literal, using the extractor's own export_statement positions (the AST already knows which export default is real) rather than a masker. Or, when several statements name nodes, prefer the one at module scope by AST.
Related: #2432 (introduced the stated-default reading), #2967.
- 主要言語
- C
- スター
- 73.2k
- フォーク
- 4.7k
- 平均マージ
- 3時間 31分
- マージ済み PR(30日)
- 546
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
colbymchenry/codegraph のほかの issue
-
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 function対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
colbymchenry/codegraph#3093 ·
メンテナーはふだん 1 日以内に返信
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launchオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
colbymchenry/codegraph#3054 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
colbymchenry/codegraph#2974 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
colbymchenry/codegraph#2959 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
colbymchenry/codegraph#1900 · コメント 2 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
colbymchenry/codegraph の issue をすべて見る
似ている issue
-
Status: Opened Type: Bug
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
severity: low
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
luainkernel/lunatik#2221 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
FriendsofECCE/ECCE#731 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
zephyrproject-rtos/zephyr#124160 ·
メンテナーはふだん 3 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
davatorium/rofi#2347 ·