Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

JS/TS: an `export default NAME` line inside a template literal is taken as the module's default export

未关闭
#2,968 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@johnhldiver-beep 已经在做这个了。

开始于 2026年10月30日。

  • #3042 来自 @johnhldiver-beep —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
64/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

colbymchenry/codegraph 的其他 Issue

查看 colbymchenry/codegraph 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。