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 小时 15 分钟
- 30 天内合并 PR
- 576
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
colbymchenry/codegraph 的其他 Issue
-
mcp: a projectPath naming a file inside a project returns isError ("Path is not a directory")可能已有人在做 @maxmilian 于 1 天前认领。 未关闭
难度 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 于 2 天前认领。 未关闭
难度 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 于 2 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
colbymchenry/codegraph#2971 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
colbymchenry/codegraph#2959 · 1 条评论 ·
维护者通常 1 天内回复
查看 colbymchenry/codegraph 的全部 Issue
相似的 Issue
-
vim.filetype.match() prefixes a URL buffer name with the cwd before passing it to filetype functions未关闭
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
stream_curl: retry_count never resets after a successful reconnect, so long sequential streams die after 5 drops可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
mpv-player/mpv#18728 ·
维护者通常 1 天内回复
-
followup Prio 📌
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
cyrusimap/cyrus-imapd#6640 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 60/100
维护者通常 1 天内回复