typescript/ast/scanner: scan() never advances past `#` not followed by an identifier start (7.1.0-beta)

オープン
#65,075 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
compilers

調査の方向性

Start with the createScanner entry point in typescript/ast/scanner and run the provided reproduction on the three inputs. Trace the # scanning behavior when no identifier start follows, then check existing scanner tests for where to add regression coverage. Done means each scan advances or returns EndOfFile, and the inputs produce tokens that do not repeat at the same position.

索引モデルが issue の本文から書いたものです。

説明

🔎 Search Terms

createScanner, scan, PrivateIdentifier, #, infinite loop, scanner does not advance, typescript/ast/scanner

🕗 Version & Regression Information
  • Reproduces in [email protected] (typescript/ast/scanner). The JS scanner is used through the new API entry points.
  • Does not reproduce in [email protected] (ts.createScanner).
  • Node 22.22.3, Linux x64.
⏯ Playground Link

No response

💻 Code
// node repro.mjs
import { createScanner } from "typescript/ast/scanner";
import { SyntaxKind } from "typescript/ast";

for (const text of ["a # b", "# ", "#1"]) {
  const scanner = createScanner(/*skipTrivia*/ true, /*languageVariant*/ undefined, text);
  const tokens = [];
  for (let i = 0; i < 6; i++) {
    const kind = scanner.scan();
    tokens.push(`${SyntaxKind[kind]}@${scanner.getTokenStart()}-${scanner.getTokenEnd()}`);
    if (kind === SyntaxKind.EndOfFile) break;
  }
  console.log(JSON.stringify(text), tokens.join(", "));
}
🙁 Actual behavior

When # is not followed by an identifier start, scan() returns PrivateIdentifier with an empty range and never advances, so it never reaches EndOfFile:

"a # b" Identifier@0-1, PrivateIdentifier@2-2, PrivateIdentifier@2-2, PrivateIdentifier@2-2, PrivateIdentifier@2-2, PrivateIdentifier@2-2
"# "    PrivateIdentifier@0-0, PrivateIdentifier@0-0, ...
"#1"    PrivateIdentifier@0-0, PrivateIdentifier@0-0, ...

Any loop of the form while (scanner.scan() !== SyntaxKind.EndOfFile) hangs on such input.

🙂 Expected behavior

The scanner consumes the # and moves on, as [email protected] does:

"a # b" Identifier@0, PrivateIdentifier@2, Identifier@4, EndOfFileToken@5
"# "    PrivateIdentifier@0, EndOfFileToken@2
"#1"    PrivateIdentifier@0, NumericLiteral@1, EndOfFileToken@2

(5.9 also reports an "Invalid character" error for the lone #.) At minimum, every scan() call should advance the position or return EndOfFile.

Additional information about the issue

Input like this is common in tooling that scans arbitrary text, such as comments, markdown-ish strings, and partial edits.

主要言語
Go
スター
112k
フォーク
15.4k
平均マージ
3日 6時間
マージ済み PR(30日)
136

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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