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

Aberta
#65,075 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
70/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
compilers

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

🔎 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.

Linguagem predominante
Go
Estrelas
112k
Forks
16k
Merge médio
3d 4h
PRs com merge (30d)
145

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de microsoft/TypeScript

Todas as issues de microsoft/TypeScript

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.