Tokenize regex flags as 'keyword.other' like VS Code does

This commit is contained in:
Sebastian Pahnke 2018-10-01 08:30:48 +02:00
parent 3e6c3ee653
commit ce3a0652b3
3 changed files with 68 additions and 2 deletions

View file

@ -446,6 +446,39 @@ testTokenization('javascript', [
] ]
}], }],
[{
line: '/foo/',
tokens: [
{ startIndex: 0, type: 'regexp.js' }
]
}],
[{
line: '/foo/g',
tokens: [
{ startIndex: 0, type: 'regexp.js' },
{ startIndex: 5, type: 'keyword.other.js' }
]
}],
[{
line: '/foo/gimsuy',
tokens: [
{ startIndex: 0, type: 'regexp.js' },
{ startIndex: 5, type: 'keyword.other.js' }
]
}],
[{
line: '/foo/q', // invalid flag
tokens: [
{ startIndex: 0, type: 'delimiter.js' },
{ startIndex: 1, type: 'identifier.js' },
{ startIndex: 4, type: 'delimiter.js' },
{ startIndex: 5, type: 'identifier.js' }
]
}],
[{ [{
line: 'x = 1 + f(2 / 3, /foo/)', line: 'x = 1 + f(2 / 3, /foo/)',
tokens: [ tokens: [

View file

@ -446,6 +446,39 @@ testTokenization('typescript', [
] ]
}], }],
[{
line: '/foo/',
tokens: [
{ startIndex: 0, type: 'regexp.ts' }
]
}],
[{
line: '/foo/g',
tokens: [
{ startIndex: 0, type: 'regexp.ts' },
{ startIndex: 5, type: 'keyword.other.ts' }
]
}],
[{
line: '/foo/gimsuy',
tokens: [
{ startIndex: 0, type: 'regexp.ts' },
{ startIndex: 5, type: 'keyword.other.ts' }
]
}],
[{
line: '/foo/q', // invalid flag
tokens: [
{ startIndex: 0, type: 'delimiter.ts' },
{ startIndex: 1, type: 'identifier.ts' },
{ startIndex: 4, type: 'delimiter.ts' },
{ startIndex: 5, type: 'identifier.ts' }
]
}],
[{ [{
line: 'x = 1 + f(2 / 3, /foo/)', line: 'x = 1 + f(2 / 3, /foo/)',
tokens: [ tokens: [

View file

@ -190,7 +190,7 @@ export const language = {
[/[^\\\/]/, 'regexp'], [/[^\\\/]/, 'regexp'],
[/@regexpesc/, 'regexp.escape'], [/@regexpesc/, 'regexp.escape'],
[/\\\./, 'regexp.invalid'], [/\\\./, 'regexp.invalid'],
['/', { token: 'regexp', bracket: '@close' }, '@pop'], [/(\/)([gimsuy]*)/, [{ token: 'regexp', bracket: '@close', next: '@pop' }, 'keyword.other']],
], ],
regexrange: [ regexrange: [