Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの 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 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #3042 @johnhldiver-beep による — マージされずにクローズ
  • #3068 @colbymchenry による — マージ済み

評価

難易度
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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

colbymchenry/codegraph のほかの issue

colbymchenry/codegraph の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。