microsoft / TypeScript-TmLanguage

TextMate grammar files for TypeScript for VS Code, Sublime Text, and Atom.
MIT License
413 stars 126 forks source link

Tokenising failure on parenthesis-wrapped object literal's type assertion operators `as keyof typeof` #995

Open OzelotVanilla opened 11 months ago

OzelotVanilla commented 11 months ago

JavaScript and TypeScript Nightly version: 5.3.0-dev.20231015

Code

This is the minimal and possible code for compare and constrast. The example might not cover all posibilities that leads to this issue.

type A = { a: "", b: "" }
const a = { a: "", b: "" }

const c = ({
    key: a.a, label: a.b[a.a as keyof typeof a.b]
})

const d = (
    {
        key: a.a, label: a.b[a.a as keyof typeof a.b]
    })

const e =
    { key: a.a, label: a.b[a.a as keyof typeof a.b] }

const f =
{
    key: a.a, label: a.b[a.a as keyof typeof a.b]
}

When the object literal is going to be written like d, the inner operator as keyof typeof is tokenised as variable.parameter.ts or (tsx), but not keyword.*.

image