Update with more JSX fixes.

pull/4650/head
The Software Philosopher 5 months ago committed by GitHub
parent 15e3e5b806
commit 9f902e753e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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: [ ctrlKeywords: [
'export', 'export', 'default', 'return', 'as', 'if', 'break', 'case', 'catch', 'continue',
'default', 'do', 'else', 'finally', 'for', 'throw', 'try', 'with', 'yield', 'await',
'return', 'import', 'from', 'type',
'as',
'if',
'break',
'case',
'catch',
'continue',
'do',
'else',
'finally',
'for',
'throw',
'try',
'with',
'yield',
'await',
'import',
'from',
'type'
], ],
alwaysKeyword: ['constructor', 'super'], 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
@ -218,271 +131,249 @@ export const language = {
// The main tokenizer for our languages // The main tokenizer for our languages
tokenizer: { tokenizer: {
root: [ root: [
[ [/}/, {
/}/, cases: {
{ '$S2==INJSX': { token: '@brackets', next: '@pop' },
cases: { '@default': '@brackets',
'$S2==INJSX': { token: '@brackets', next: '@pop' }, }
'@default': '@brackets' }],
}
} [/{/, 'delimiter.bracket'],
],
// highlight class field-properties
[/{/, 'delimiter.bracket'], [/^\s+#?[\w$]+(?=\s*[;=:])/, 'variable.property'],
// highlight class field-properties // highlight function/class defs
[/^\s+#?[\w$]+(?=\s*[;=:])/, 'variable.property'], [/(function|class|new)(\s+)(#?[\w$]+)(\s*)([<(]?)/, ['keyword', '',
{
// highlight function/class defs cases: {
[ '$1==function': 'method',
/(function|class|new)(\s+)(#?[\w$]+)(\s*)([<(]?)/, '$1==class': 'type.identifier',
[ '$1==new': 'type.identifier',
'keyword', }
'', }, '', {
{ cases: {
cases: { '<': { token: '@brackets', next: '@typeparams' },
'$1==function': 'method', '@default': '@rematch',
'$1==class': 'type.identifier', }
'$1==new': 'type.identifier' },
} ]],
},
'', // highlight var/const/let defs
{ [/(const|let|var)(\s+)(#?[\w$]+)/, ['keyword', '', {
cases: { cases: {
'<': { token: '@brackets', next: '@typeparams' }, '$1==const': 'constant',
'@default': '@rematch' '@default': 'variable',
} }
} }]],
]
], { include: 'jsxReady' },
// highlight var/const/let defs { include: 'common' },
[ ],
/(const|let|var)(\s+)(#?[\w$]+)/,
[ common: [
'keyword',
'', // identifiers and keywords
{ [/(#?[a-zA-Z_$][\w$]*)([<(]?)/, [
cases: { {
'$1==const': 'constant', cases: {
'@default': 'variable' '@typeKeywords': 'type.identifier',
} '@alwaysKeyword': 'keyword',
} '$1~#?[A-Z].*': 'type.identifier',
] '$2': 'method',
], '@ctrlKeywords': 'keyword.flow',
'@keywords': 'keyword',
{ include: 'jsxReady' }, '@default': 'identifier',
}
{ include: 'common' } },
], {
cases: {
common: [ '$2==<': { token: '@brackets', next: '@typeparams' },
// identifiers and keywords '@default': '@rematch',
[ }
/(#?[a-zA-Z_$][\w$]*)([<(]?)/, },
[ ]],
{
cases: {
'@typeKeywords': 'type.identifier',
'@alwaysKeyword': 'keyword',
'$1~#?[A-Z].*': 'type.identifier',
$2: 'method',
'@ctrlKeywords': 'keyword.flow',
'@keywords': 'keyword',
'@default': 'identifier'
}
},
{
cases: {
'$2==<': { token: '@brackets', next: '@typeparams' },
'@default': '@rematch'
}
}
]
],
// whitespace
{ include: '@whitespace' },
// regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
[
/\/(?=([^\\\/]|\\.)+\/([dgimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/,
{ token: 'regexp', bracket: '@open', next: '@regexp' }
],
// delimiters and operators
[/[()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'],
[/!(?=([^=]|$))/, 'delimiter'],
[
/@symbols/,
{
cases: {
'@operators': 'delimiter',
'@default': ''
}
}
],
[/\.\.\./, 'keyword'],
// numbers
[/(@digits)[eE]([\-+]?(@digits))?/, 'number.float'],
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, 'number.float'],
[/0[xX](@hexdigits)n?/, 'number.hex'],
[/0[oO]?(@octaldigits)n?/, 'number.octal'],
[/0[bB](@binarydigits)n?/, 'number.binary'],
[/(@digits)n?/, 'number'],
// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
[/'([^'\\]|\\.)*$/, 'string.invalid'], // non-teminated string
[/"/, 'string', '@string_double'],
[/'/, 'string', '@string_single'],
[/`/, 'string', '@string_backtick']
],
typeparams: [[/>/, '@brackets', '@pop'], { include: 'common' }],
jsxReady: [
[/<>/, 'delimiter.html', '@jsxText.FRAGMENT'],
[
/(<)([A-Z][\w$]*\s*(?:,|extends|implements))/,
['@brackets', { token: '@rematch', next: '@typeparams' }]
],
[/(<)(\s*)([\w$])/, ['delimiter.html', '', { token: '@rematch', next: '@jsxIdent.jsxOpen.' }]]
],
jsxIdent: [
[/\./, { token: 'delimiter', switchTo: '$S0^' }],
[/[A-Z][\w$]*/, { token: 'type.identifier', switchTo: '$S0$0' }],
[/[\w$]+/, { token: 'tag', switchTo: '$S0$0' }],
[/.+/, { token: '@rematch', switchTo: '@$S2.$S3.$S4' }]
],
jsxOpen: [
[/>/, { token: 'delimiter.html', switchTo: '@jsxText.$S2' }],
[/\/>/, { token: 'delimiter.html', next: '@pop' }],
[/ +([\w-$]+)/, 'attribute.name'],
[/(=)(')/, ['delimiter', { token: 'string', next: '@string_single' }]],
[/(=)(")/, ['delimiter', { token: 'string', next: '@string_double' }]],
[/(=)({)/, ['delimiter', { token: '@brackets', next: '@root.INJSX' }]]
],
jsxText: [
[/{/, { token: 'keyword', next: '@root.INJSX', bracket: '@open' }],
[
/<\/>/,
{
cases: {
'$S2==FRAGMENT': { token: 'delimiter.html', next: '@pop' },
'@default': { token: 'invalid', next: '@pop' }
}
}
],
[
/(<\/)(\s*)([\w$])/,
['delimiter.html', '', { token: '@rematch', switchTo: '@jsxIdent.jsxClose.$S2.' }]
],
{ include: 'jsxReady' },
[/./, 'string']
],
jsxClose: [
[
/>/,
{
cases: {
'$S2==$S3': { token: 'delimiter.html', next: '@pop' },
'@default': { token: 'invalid', next: '@pop' }
}
}
]
],
whitespace: [
[/[ \t\r\n]+/, ''],
[/\/\*\*(?!\/)/, 'comment.doc', '@jsdoc'],
[/\/\*/, 'comment', '@comment'],
[/\/\/.*$/, 'comment']
],
comment: [
[/[^\/*]+/, 'comment'],
[/\*\//, 'comment', '@pop'],
[/[\/*]/, 'comment']
],
jsdoc: [
[/[^\/*]+/, 'comment.doc'],
[/\*\//, 'comment.doc', '@pop'],
[/[\/*]/, 'comment.doc']
],
// We match regular expression quite precisely // whitespace
regexp: [ { include: '@whitespace' },
[
/(\{)(\d+(?:,\d*)?)(\})/,
['regexp.escape.control', 'regexp.escape.control', 'regexp.escape.control']
],
[
/(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/,
['regexp.escape.control', { token: 'regexp.escape.control', next: '@regexrange' }]
],
[/(\()(\?:|\?=|\?!)/, ['regexp.escape.control', 'regexp.escape.control']],
[/[()]/, 'regexp.escape.control'],
[/@regexpctl/, 'regexp.escape.control'],
[/[^\\\/]/, 'regexp'],
[/@regexpesc/, 'regexp.escape'],
[/\\\./, 'regexp.invalid'],
[/(\/)([dgimsuy]*)/, [{ token: 'regexp', bracket: '@close', next: '@pop' }, 'keyword.other']]
],
regexrange: [ // regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
[/-/, 'regexp.escape.control'], [
[/\^/, 'regexp.invalid'], /\/(?=([^\\\/]|\\.)+\/([dgimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/,
[/@regexpesc/, 'regexp.escape'], { token: 'regexp', bracket: '@open', next: '@regexp' }
[/[^\]]/, 'regexp'],
[
/\]/,
{
token: 'regexp.escape.control',
next: '@pop',
bracket: '@close'
}
]
], ],
string_double: [ // delimiters and operators
[/[^\\"]+/, 'string'], [/[()\[\]]/, '@brackets'],
[/@escapes/, 'string.escape'], [/[<>](?!@symbols)/, '@brackets'],
[/\\./, 'string.escape.invalid'], [/!(?=([^=]|$))/, 'delimiter'],
[/"/, 'string', '@pop'] [
/@symbols/,
{
cases: {
'@operators': 'delimiter',
'@default': ''
}
}
], ],
string_single: [ [/\.\.\./, 'keyword'],
[/[^\\']+/, 'string'],
[/@escapes/, 'string.escape'], // numbers
[/\\./, 'string.escape.invalid'], [/(@digits)[eE]([\-+]?(@digits))?/, 'number.float'],
[/'/, 'string', '@pop'] [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, 'number.float'],
[/0[xX](@hexdigits)n?/, 'number.hex'],
[/0[oO]?(@octaldigits)n?/, 'number.octal'],
[/0[bB](@binarydigits)n?/, 'number.binary'],
[/(@digits)n?/, 'number'],
// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
[/'([^'\\]|\\.)*$/, 'string.invalid'], // non-teminated string
[/"/, 'string', '@string_double'],
[/'/, 'string', '@string_single'],
[/`/, 'string', '@string_backtick']
],
typeparams: [
[/>/, '@brackets', '@pop'],
{ include: 'common' }
],
jsxReady: [
[/<>/, 'delimiter.html', '@jsxText.FRAGMENT'],
[/(<)([A-Z][\w$]*\s*(?:,|extends|implements))/, ['@brackets', { token: '@rematch', next: '@typeparams' }]],
[/(<)(\s*)([\w$])/, ['delimiter.html', '',
{ token: '@rematch', next: '@jsxIdent.jsxOpen.' },
]],
],
jsxIdent: [
[/\./, { token: 'delimiter', switchTo: '$S0^' }],
[/[A-Z][\w$]*/, { token: 'type.identifier', switchTo: '$S0$0' }],
[/[\w$-]+/, { token: 'tag', switchTo: '$S0$0' }],
[/.+/, { token: '@rematch', switchTo: '@$S2.$S3.$S4' }],
],
jsxOpen: [
[/{/, { token: 'keyword', next: '@root.INJSX', bracket: '@open' }],
[/>/, { token: 'delimiter.html', switchTo: '@jsxText.$S2' }],
[/\/>/, { token: 'delimiter.html', next: '@pop' }],
[/ +([\w-$]+)/, 'attribute.name'],
[/(=)(')/, ['delimiter', { token: 'string', next: '@string_single' }]],
[/(=)(")/, ['delimiter', { token: 'string', next: '@string_double' }]],
[/(=)({)/, ['delimiter', { token: '@brackets', next: '@root.INJSX' }]],
],
jsxText: [
[/{/, { token: 'keyword', next: '@root.INJSX', bracket: '@open' }],
[/<\/>/, {
cases: {
'$S2==FRAGMENT': { token: 'delimiter.html', next: '@pop' },
'@default': { token: 'invalid', next: '@pop' },
}
}],
[/(<\/)(\s*)([\w$])/, ['delimiter.html', '',
{ token: '@rematch', switchTo: '@jsxIdent.jsxClose.$S2.' },
]],
{ include: 'jsxReady' },
[/./, 'string'],
],
jsxClose: [
[/>/, {
cases: {
'$S2==$S3': { token: 'delimiter.html', next: '@pop' },
'@default': { token: 'invalid', next: '@pop' },
}
}],
],
whitespace: [
[/[ \t\r\n]+/, ''],
[/\/\*\*(?!\/)/, 'comment.doc', '@jsdoc'],
[/\/\*/, 'comment', '@comment'],
[/\/\/.*$/, 'comment']
],
comment: [
[/[^\/*]+/, 'comment'],
[/\*\//, 'comment', '@pop'],
[/[\/*]/, 'comment']
],
jsdoc: [
[/[^\/*]+/, 'comment.doc'],
[/\*\//, 'comment.doc', '@pop'],
[/[\/*]/, 'comment.doc']
],
// We match regular expression quite precisely
regexp: [
[
/(\{)(\d+(?:,\d*)?)(\})/,
['regexp.escape.control', 'regexp.escape.control', 'regexp.escape.control']
], ],
[
string_backtick: [ /(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/,
[/\$\{/, { token: 'delimiter.bracket', next: '@bracketCounting' }], ['regexp.escape.control', { token: 'regexp.escape.control', next: '@regexrange' }]
[/[^\\`$]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/`/, 'string', '@pop']
], ],
[/(\()(\?:|\?=|\?!)/, ['regexp.escape.control', 'regexp.escape.control']],
bracketCounting: [ [/[()]/, 'regexp.escape.control'],
[/\{/, 'delimiter.bracket', '@bracketCounting'], [/@regexpctl/, 'regexp.escape.control'],
[/\}/, 'delimiter.bracket', '@pop'], [/[^\\\/]/, 'regexp'],
{ include: 'common' } [/@regexpesc/, 'regexp.escape'],
[/\\\./, 'regexp.invalid'],
[/(\/)([dgimsuy]*)/, [{ token: 'regexp', bracket: '@close', next: '@pop' }, 'keyword.other']]
],
regexrange: [
[/-/, 'regexp.escape.control'],
[/\^/, 'regexp.invalid'],
[/@regexpesc/, 'regexp.escape'],
[/[^\]]/, 'regexp'],
[
/\]/,
{
token: 'regexp.escape.control',
next: '@pop',
bracket: '@close'
}
] ]
],
string_double: [
[/[^\\"]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/"/, 'string', '@pop']
],
string_single: [
[/[^\\']+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/'/, 'string', '@pop']
],
string_backtick: [
[/\$\{/, { token: 'delimiter.bracket', next: '@bracketCounting' }],
[/[^\\`$]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/`/, 'string', '@pop']
],
bracketCounting: [
[/\{/, 'delimiter.bracket', '@bracketCounting'],
[/\}/, 'delimiter.bracket', '@pop'],
{ include: 'common' }
]
} }
}; };

Loading…
Cancel
Save