microsoft / microsoft/TypeScript-TmLanguage

TextMate tokenizer enters incorrect scope after typeof a < "u" in JavaScript, affecting subsequent function declarations

Offen
#1,076 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
TypeScript
Sterne
471
Forks
149
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

VS Code Version

Version: 1.124.2 (user setup)
Commit: 6928394f91b684055b873eecb8bc281365131f1c
Date: 2026-06-12T00:12:36Z
Electron: 42.2.0
ElectronBuildId: 14159160
Chromium: 148.0.7778.97
Node.js: 24.15.0
V8: 14.8.178.14-electron.0
OS: Windows_NT x64 10.0.26200

Fresh install of VS Code with all default settings. No extensions installed, no custom configuration applied.
Also reproduced on VS Code for the Web (vscode.dev) with no extensions or custom configuration.

Reproducible Example

function bar() {
  return "bar";
}

var a = typeof a < "u";

function foo() {
  return "foo";
}

Steps to Reproduce

  1. Install VS Code with all default settings (no extensions, no custom configuration).
  2. Create a new .js file.
  3. Paste the code above.
  4. Run:
Developer: Inspect Editor Tokens and Scopes
  1. Inspect the first function keyword (bar declaration).
  2. Inspect the second function keyword (foo declaration).

Actual Result

The first function declaration is tokenized correctly:

storage.type.function.js
meta.function.js
source.js

The second function declaration is tokenized incorrectly:

entity.name.type.js
meta.type.parameters.js
meta.var.expr.js
source.js

Syntax highlighting becomes incorrect for all code following:

var a = typeof a < "u";

Expected Result

The second function declaration should receive the same scopes as the first:

storage.type.function.js
meta.function.js
source.js

No tokenizer state should leak past the end of the variable declaration.

Additional Investigation

Replacing:

var a = typeof a < "u";

with:

var a = typeof a > "u";
Image immediately fixes the issue. The second `function` is then correctly scoped as:

Notes

  • Reproduced on a fresh VS Code install with all default settings and no extensions.
  • Reproduced across all built-in themes; the issue is not theme-specific.
  • The JavaScript is syntactically valid.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das Beispiel in einer JavaScript-Datei zu reproduzieren, und verwende „Developer: Inspect Editor Tokens and Scopes“, um die beiden Funktionsdeklarationen zu vergleichen. Verfolge die TextMate-Grammatikregeln, die typeof a < "u" und die darauffolgende Deklaration behandeln; abgeschlossen ist die Aufgabe, wenn die zweite Funktion dieselben Scopes wie die erste erhält und der Tokenizer-Zustand nicht mehr in nachfolgenden Code ausläuft.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.