Update with more JSX fixes.

This commit is contained in:
The Software Philosopher 2024-09-10 07:55:17 -05:00 committed by GitHub
parent 15e3e5b806
commit 9f902e753e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,134 +75,47 @@ export const conf: languages.LanguageConfiguration = {
}; };
export const language = { export const language = {
defaultToken: 'invalid', defaultToken: 'invalid',
tokenPostfix: '.ts', tokenPostfix: '.ts',
typeKeywords: ['any', 'bigint', 'boolean', 'number', 'object', 'string', 'unknown', 'void'], typeKeywords: [
'any', 'bigint', 'boolean', 'number', 'object', 'string', 'unknown', 'void',
ctrlKeywords: [
'export',
'default',
'return',
'as',
'if',
'break',
'case',
'catch',
'continue',
'do',
'else',
'finally',
'for',
'throw',
'try',
'with',
'yield',
'await',
'import',
'from',
'type'
], ],
alwaysKeyword: ['constructor', 'super'], ctrlKeywords: [
'export', 'default', 'return', 'as', 'if', 'break', 'case', 'catch', 'continue',
'do', 'else', 'finally', 'for', 'throw', 'try', 'with', 'yield', 'await',
'import', 'from', 'type',
],
alwaysKeyword: [
'constructor', 'super',
],
keywords: [ keywords: [
// Should match the keys of textToKeywordObj in // Should match the keys of textToKeywordObj in
// https://github.com/microsoft/TypeScript/blob/master/src/compiler/scanner.ts // https://github.com/microsoft/TypeScript/blob/master/src/compiler/scanner.ts
'abstract', 'abstract', 'asserts',
'asserts', 'class', 'const', 'debugger',
'class', 'declare', 'delete', 'enum',
'const', 'extends', 'false', 'function', 'get',
'debugger', 'implements', 'in', 'infer', 'instanceof', 'interface',
'declare', 'is', 'keyof', 'let', 'module', 'namespace', 'never', 'new',
'delete', 'null', 'out', 'package', 'private', 'protected',
'enum', 'public', 'override', 'readonly', 'require', 'global', 'satisfies',
'extends', 'set', 'static', 'switch', 'symbol', 'this',
'false', 'true', 'typeof', 'undefined', 'unique',
'function', 'var', 'while', 'async', 'of'
'get',
'implements',
'in',
'infer',
'instanceof',
'interface',
'is',
'keyof',
'let',
'module',
'namespace',
'never',
'new',
'null',
'out',
'package',
'private',
'protected',
'public',
'override',
'readonly',
'require',
'global',
'satisfies',
'set',
'static',
'switch',
'symbol',
'this',
'true',
'typeof',
'undefined',
'unique',
'var',
'while',
'async',
'of'
], ],
operators: [ operators: [
'<=', '<=', '>=', '==', '!=', '===', '!==', '=>',
'>=', '+', '-', '**', '*', '/', '%', '++',
'==', '--', '<<', '</', '>>', '>>>', '&', '|',
'!=', '^', '!', '~', '&&', '||', '??', '?',
'===', ':', '=', '+=', '-=', '*=', '**=', '/=',
'!==', '%=', '<<=', '>>=', '>>>=', '&=', '|=', '^=', '@'
'=>',
'+',
'-',
'**',
'*',
'/',
'%',
'++',
'--',
'<<',
'</',
'>>',
'>>>',
'&',
'|',
'^',
'!',
'~',
'&&',
'||',
'??',
'?',
':',
'=',
'+=',
'-=',
'*=',
'**=',
'/=',
'%=',
'<<=',
'>>=',
'>>>=',
'&=',
'|=',
'^=',
'@'
], ],
// we include these common regular expressions // we include these common regular expressions
@ -219,15 +132,12 @@ export const language = {
// The main tokenizer for our languages // The main tokenizer for our languages
tokenizer: { tokenizer: {
root: [ root: [
[ [/}/, {
/}/,
{
cases: { cases: {
'$S2==INJSX': { token: '@brackets', next: '@pop' }, '$S2==INJSX': { token: '@brackets', next: '@pop' },
'@default': '@brackets' '@default': '@brackets',
} }
} }],
],
[/{/, 'delimiter.bracket'], [/{/, 'delimiter.bracket'],
@ -235,72 +145,56 @@ export const language = {
[/^\s+#?[\w$]+(?=\s*[;=:])/, 'variable.property'], [/^\s+#?[\w$]+(?=\s*[;=:])/, 'variable.property'],
// highlight function/class defs // highlight function/class defs
[ [/(function|class|new)(\s+)(#?[\w$]+)(\s*)([<(]?)/, ['keyword', '',
/(function|class|new)(\s+)(#?[\w$]+)(\s*)([<(]?)/,
[
'keyword',
'',
{ {
cases: { cases: {
'$1==function': 'method', '$1==function': 'method',
'$1==class': 'type.identifier', '$1==class': 'type.identifier',
'$1==new': 'type.identifier' '$1==new': 'type.identifier',
} }
}, }, '', {
'',
{
cases: { cases: {
'<': { token: '@brackets', next: '@typeparams' }, '<': { token: '@brackets', next: '@typeparams' },
'@default': '@rematch' '@default': '@rematch',
} }
} },
] ]],
],
// highlight var/const/let defs // highlight var/const/let defs
[ [/(const|let|var)(\s+)(#?[\w$]+)/, ['keyword', '', {
/(const|let|var)(\s+)(#?[\w$]+)/,
[
'keyword',
'',
{
cases: { cases: {
'$1==const': 'constant', '$1==const': 'constant',
'@default': 'variable' '@default': 'variable',
} }
} }]],
]
],
{ include: 'jsxReady' }, { include: 'jsxReady' },
{ include: 'common' } { include: 'common' },
], ],
common: [ common: [
// identifiers and keywords // identifiers and keywords
[ [/(#?[a-zA-Z_$][\w$]*)([<(]?)/, [
/(#?[a-zA-Z_$][\w$]*)([<(]?)/,
[
{ {
cases: { cases: {
'@typeKeywords': 'type.identifier', '@typeKeywords': 'type.identifier',
'@alwaysKeyword': 'keyword', '@alwaysKeyword': 'keyword',
'$1~#?[A-Z].*': 'type.identifier', '$1~#?[A-Z].*': 'type.identifier',
$2: 'method', '$2': 'method',
'@ctrlKeywords': 'keyword.flow', '@ctrlKeywords': 'keyword.flow',
'@keywords': 'keyword', '@keywords': 'keyword',
'@default': 'identifier' '@default': 'identifier',
} }
}, },
{ {
cases: { cases: {
'$2==<': { token: '@brackets', next: '@typeparams' }, '$2==<': { token: '@brackets', next: '@typeparams' },
'@default': '@rematch' '@default': '@rematch',
} }
} },
] ]],
],
// whitespace // whitespace
{ include: '@whitespace' }, { include: '@whitespace' },
@ -346,62 +240,58 @@ export const language = {
[/`/, 'string', '@string_backtick'] [/`/, 'string', '@string_backtick']
], ],
typeparams: [[/>/, '@brackets', '@pop'], { include: 'common' }], typeparams: [
[/>/, '@brackets', '@pop'],
{ include: 'common' }
],
jsxReady: [ jsxReady: [
[/<>/, 'delimiter.html', '@jsxText.FRAGMENT'], [/<>/, 'delimiter.html', '@jsxText.FRAGMENT'],
[ [/(<)([A-Z][\w$]*\s*(?:,|extends|implements))/, ['@brackets', { token: '@rematch', next: '@typeparams' }]],
/(<)([A-Z][\w$]*\s*(?:,|extends|implements))/, [/(<)(\s*)([\w$])/, ['delimiter.html', '',
['@brackets', { token: '@rematch', next: '@typeparams' }] { token: '@rematch', next: '@jsxIdent.jsxOpen.' },
], ]],
[/(<)(\s*)([\w$])/, ['delimiter.html', '', { token: '@rematch', next: '@jsxIdent.jsxOpen.' }]]
], ],
jsxIdent: [ jsxIdent: [
[/\./, { token: 'delimiter', switchTo: '$S0^' }], [/\./, { token: 'delimiter', switchTo: '$S0^' }],
[/[A-Z][\w$]*/, { token: 'type.identifier', switchTo: '$S0$0' }], [/[A-Z][\w$]*/, { token: 'type.identifier', switchTo: '$S0$0' }],
[/[\w$]+/, { token: 'tag', switchTo: '$S0$0' }], [/[\w$-]+/, { token: 'tag', switchTo: '$S0$0' }],
[/.+/, { token: '@rematch', switchTo: '@$S2.$S3.$S4' }] [/.+/, { token: '@rematch', switchTo: '@$S2.$S3.$S4' }],
], ],
jsxOpen: [ jsxOpen: [
[/{/, { token: 'keyword', next: '@root.INJSX', bracket: '@open' }],
[/>/, { token: 'delimiter.html', switchTo: '@jsxText.$S2' }], [/>/, { token: 'delimiter.html', switchTo: '@jsxText.$S2' }],
[/\/>/, { token: 'delimiter.html', next: '@pop' }], [/\/>/, { token: 'delimiter.html', next: '@pop' }],
[/ +([\w-$]+)/, 'attribute.name'], [/ +([\w-$]+)/, 'attribute.name'],
[/(=)(')/, ['delimiter', { token: 'string', next: '@string_single' }]], [/(=)(')/, ['delimiter', { token: 'string', next: '@string_single' }]],
[/(=)(")/, ['delimiter', { token: 'string', next: '@string_double' }]], [/(=)(")/, ['delimiter', { token: 'string', next: '@string_double' }]],
[/(=)({)/, ['delimiter', { token: '@brackets', next: '@root.INJSX' }]] [/(=)({)/, ['delimiter', { token: '@brackets', next: '@root.INJSX' }]],
], ],
jsxText: [ jsxText: [
[/{/, { token: 'keyword', next: '@root.INJSX', bracket: '@open' }], [/{/, { token: 'keyword', next: '@root.INJSX', bracket: '@open' }],
[ [/<\/>/, {
/<\/>/,
{
cases: { cases: {
'$S2==FRAGMENT': { token: 'delimiter.html', next: '@pop' }, '$S2==FRAGMENT': { token: 'delimiter.html', next: '@pop' },
'@default': { token: 'invalid', next: '@pop' } '@default': { token: 'invalid', next: '@pop' },
} }
} }],
], [/(<\/)(\s*)([\w$])/, ['delimiter.html', '',
[ { token: '@rematch', switchTo: '@jsxIdent.jsxClose.$S2.' },
/(<\/)(\s*)([\w$])/, ]],
['delimiter.html', '', { token: '@rematch', switchTo: '@jsxIdent.jsxClose.$S2.' }]
],
{ include: 'jsxReady' }, { include: 'jsxReady' },
[/./, 'string'] [/./, 'string'],
], ],
jsxClose: [ jsxClose: [
[ [/>/, {
/>/,
{
cases: { cases: {
'$S2==$S3': { token: 'delimiter.html', next: '@pop' }, '$S2==$S3': { token: 'delimiter.html', next: '@pop' },
'@default': { token: 'invalid', next: '@pop' } '@default': { token: 'invalid', next: '@pop' },
} }
} }],
]
], ],
whitespace: [ whitespace: [
@ -485,4 +375,5 @@ export const language = {
{ include: 'common' } { include: 'common' }
] ]
} }
}; };