Skip to content

TypeScript keywords #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
keshavsaharia opened this issue Apr 16, 2025 · 6 comments
Closed

TypeScript keywords #45

keshavsaharia opened this issue Apr 16, 2025 · 6 comments

Comments

@keshavsaharia
Copy link

I am looking to contribute a minor update to the parser in the way it handles TypeScript keywords - specifically, certain TypeScript keywords like satisfies (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html) are not being correctly formatted as keywords.

Image

To include this in the grammar, would I simply need to update the javascript.grammar file?

@keshavsaharia
Copy link
Author

Also, in case Marijn Haverbeke is reading this, my sincerest gratitude for all your tireless efforts!

@marijnh
Copy link
Contributor

marijnh commented Apr 17, 2025

Unfortunately, the TypeScript project doesn't publish a complete description of all the extensions they make to the grammar, so the more obscure ones I tend to find out about only through issue reports like this. Attached patch adds the satisfies operator.

@bmeurer
Copy link
Contributor

bmeurer commented Apr 17, 2025

I just updated Chrome DevTools to @lezer/javascript 1.5.0 locally and tried both the example from this post

type StringChecker = (value: string) => boolean;

const valueChecker = function(value: string|number) {
        return true;
} satisfies StringChecker;

and the example from the TypeScript documentation

type Colors = "red" | "green" | "blue";
type RGB = [red: number, green: number, blue: number];
const palette = {
    red: [255, 0, 0],
    green: "#00ff00",
    blue: [0, 0, 255]
} satisfies Record<Colors, string | RGB>;

console.log(palette.green);

but in both cases satisfies doesn't seem to be decorated as keyword.

I didn't dig deeper yet, though.

marijnh added a commit that referenced this issue Apr 18, 2025
FIX: Properly highlight `satisfies` as a keyword.

Issue #45
@marijnh
Copy link
Contributor

marijnh commented Apr 18, 2025

I forgot to add highlighting tags to the new token. Should be fixed now.

@keshavsaharia
Copy link
Author

keshavsaharia commented Apr 23, 2025

Thank you for this latest update @marijnh , it seems like it has improved the highlighting for all TypeScript keywords. I'm using CodeMirror 6 to build a free TypeScript reference guide and have found it to be marvelously easy to add things like inline errors and highlighting. Still a work in progress but hopefully you can see some Codemirror 6 features in the wild 😃

@bmeurer
Copy link
Contributor

bmeurer commented Apr 23, 2025

Thanks Marijn!

copybara-service bot pushed a commit to ChromeDevTools/devtools-frontend that referenced this issue Apr 23, 2025
This brings support for the `satisfies` keyword and fixes the
highlighting for the `as` keyword.

Bug: none
Change-Id: I0323afd00ff835205d3f9dd0e7f566deda6c7a22
Ref: lezer-parser/javascript#45
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6483308
Commit-Queue: Benedikt Meurer <[email protected]>
Commit-Queue: Ergün Erdoğmuş <[email protected]>
Auto-Submit: Benedikt Meurer <[email protected]>
Reviewed-by: Ergün Erdoğmuş <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants