Skip to content

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

Open

Description

@soeyu

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.

Activity

  1. mohityadav8 commented on Jun 14, 2026

    @mohityadav8

    /assign
    can i work on this

  2. RedCMD commented on Jun 14, 2026

    @RedCMD

    should report to the upstream grammar repo https://github.com/microsoft/TypeScript-TmLanguage

    this should be fixable
    otherwise it can be mitigated by adding a bunch of safeguards to type to stop it from going past brackets ) and semicolons ; etc

    tho why are you trying to do this?
    typeof a < "u"
    is there a real world example that's bothering you?

  3. removed their assignment
    on Jun 16, 2026
  4. mohityadav8 commented on Jul 16, 2026

    @mohityadav8

    /working

  5. soeyu commented on Jul 27, 2026

    @soeyu
    Author

    tho why are you trying to do #this?
    typeof a < "u"
    is there a real world example that's bothering you?

    RedCMD (@RedCMD)
    I don't normally write code in this style myself. However, I sometimes inspect bundled code, and after running it through a formatter/beautifier, I discovered this issue.

  6. RedCMD commented on Jul 27, 2026

    @RedCMD

    makes sense
    is that example directly from a bundle (beautified)?
    or did you hand write it?

  7. soeyu commented on Jul 28, 2026

    @soeyu
    Author

    you can find the <`u` pattern directly in this bundled file:

    https://chatgpt.com/cdn/assets/2340486e-gh6s19h8ofjisiyk.js

    I discovered this issue when beautifying the code in VS Code with Prettier or Oxcfmt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions