Skip to content
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

Typescript, adding keywords satisfies and as to the lexer #2014

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Eunoia
Copy link

@Eunoia Eunoia commented Dec 10, 2023

Howdy!

Noticed some less than perfect syntax highlighting on a blog post, and thought to fix the issue upstream in rouge.

In typescript, 'as' and 'satisfies' are type assertion operator, while 'satisfies' is a type operator. There is no 'as' keyword in javascript, and the way the rule was written, functions named "as" were being marked as keywords, rather than functions.

I took the rule from a textmate grammar, and modified it to work in rouge.

I also tested this commit against my blog, and noticed the improved syntax highlighting there.

Now, "satisfies" and "as" are marked as keywords where they are used in a keyword way.

Here are three screenshots, before, after, and delta of visual lexer test.

Before

The "satisfies" is not bolded, and the "as" in the function names are bolded. Not ideal.
Screenshot 2023-12-09 at 5 19 53 PM

After

The "satisfies" is bolded, and the function names are not bolded, with no regressions to the other "as"
Screenshot 2023-12-09 at 5 19 13 PM

Delta

white is unchanged, teal is text that was made unbolded, and yellow is bolded.
Screenshot 2023-12-10 at 10 58 35 AM

@tancnle tancnle added the needs-review The PR needs to be reviewed label Dec 24, 2023
@tancnle tancnle self-requested a review December 24, 2023 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review The PR needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants