Skip to content

Commit

Permalink
Enter isolated state for type params to avoid JSX collisions.
Browse files Browse the repository at this point in the history
  • Loading branch information
thesoftwarephilosopher committed Aug 22, 2024
1 parent fcddf91 commit b60eefe
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions site/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
/**
* Differences from official typescript monarch token provider:
*
* 1. `...` is highlighted as a keyword now
* 1. `...` is highlighted as a keyword
* 2. `export/etc` are highlighted as control-flow keywords
* 3. Class fields are highlighted as variables
* 4. Type params are highlighted separate from JSX
*
*/

export const rules = [
// { token: "identifier.ts", foreground: "9CDCFE" },
{ token: "variable.property.ts", foreground: "9CDCFE" },
// { token: "function.ts", foreground: "DCDCAA" },
// { token: "method.ts", foreground: "DCDCAA" },
{ token: "method.ts", foreground: "DCDCAA" },
// { token: "delimiter.ts", foreground: "569CD6" },
];

Expand Down Expand Up @@ -76,12 +77,20 @@ export const tokenProvider = {
common: [
// identifiers and keywords
[
/#?[a-z_$][\w$]*/,
/(#?[a-z_$][\w$]*)([<(]?)/,
{
cases: {
'@ctrlKeywords': 'keyword.flow',
'@keywords': 'keyword',
'@default': 'identifier'
'super\\(': 'keyword',
'constructor\\(': 'keyword',
'@default': {
cases: {
'$2==<': ['method', { token: '@brackets', next: '@typeparams' }],
'$2==(': ['method', ''],
'@default': 'identifier',
}
},
}
}
],
Expand Down Expand Up @@ -132,6 +141,11 @@ export const tokenProvider = {
[/`/, 'string', '@string_backtick']
],

typeparams: [
[/>/, '@brackets', '@pop'],
{ include: 'common' }
],

whitespace: [
[/[ \t\r\n]+/, ''],
[/\/\*\*(?!\/)/, 'comment.doc', '@jsdoc'],
Expand Down

0 comments on commit b60eefe

Please sign in to comment.