@@ -11,29 +11,30 @@ patterns:
1111repository :
1212 var-expr :
1313 name : meta.var.expr.ts
14- begin : (?<!\()\s*\b(var|let|const(?!\s+enum))\s+([a-zA-Z_$][\w$]*)
14+ begin : (?<!\()\s*\b(var|let|const(?!\s+enum)\b)
1515 beginCaptures :
1616 ' 1 ' : { name: storage.type.ts }
17- ' 2 ' : { name: variable.ts }
18- end : ' (?=$|[;=\}\{])|(?<=\})'
17+ end : (?=$|;)
18+ patterns :
19+ - include : ' #var-single-variable'
20+ - include : ' #comment'
21+
22+ var-single-variable :
23+ name : meta.var-single-variable.expr.ts
24+ begin : \b([a-zA-Z_$][\w$]*)\s*(=?)
25+ beginCaptures :
26+ ' 1 ' : { name: variable.ts }
27+ end : (?=$|[;,])
1928 patterns :
2029 - include : ' #type-annotation'
2130 - include : ' #string'
2231 - include : ' #comment'
32+ - include : ' #expression'
2333
2434 control-statement :
2535 name : keyword.control.ts
2636 match : (?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\b
2737
28- switch-case :
29- name : case.expr.ts
30- begin : ' (?<!\.)\b(case|default)\b'
31- beginCaptures :
32- ' 1 ' : { name: keyword.control.ts }
33- end : ' :'
34- patterns :
35- - include : ' #expression'
36-
3738 declaration :
3839 name : meta.declaration.ts
3940 patterns :
@@ -44,13 +45,16 @@ repository:
4445
4546 type-declaration :
4647 name : meta.type.declaration.ts
47- begin : \b(type)\b\s+([a-zA-Z_$][\w$]*)\s*=\s*
48+ begin : \b(type)\b\s+([a-zA-Z_$][\w$]*)\s*
4849 beginCaptures :
4950 ' 1 ' : { name: keyword.other.ts }
5051 ' 2 ' : { name: storage.type.ts }
51- end : (?=[,);>]|var|type|function|class|interface)
52+ end : (?=$| [,);>]|var|type|function|class|interface)
5253 patterns :
54+ - include : ' #type-parameters'
5355 - include : ' #type'
56+ - name : keyword.operator.ts
57+ match : ' =\s*'
5458
5559 enum-declaration :
5660 name : meta.enum.declaration.ts
@@ -85,20 +89,21 @@ repository:
8589
8690 object-heritage :
8791 name : meta.object.heritage.ts
88- begin : ' (?:\b(extends|implements))'
92+ begin : ' (?:\b(extends|implements)\b )'
8993 beginCaptures :
9094 ' 1 ' : { name: keyword.other.ts }
9195 end : (?=\{)
9296 endCaptures :
9397 ' 1 ' : { name: brace.curly.ts }
9498 patterns :
9599 - include : ' #comment'
100+ - include : ' #object-heritage'
96101 - include : ' #type-parameters'
97- - include : ' #object-heritage-parent '
102+ - include : ' #object-heritage-type '
98103
99- object-heritage-parent :
104+ object-heritage-type :
100105 name : meta.object.heritage.parent.ts
101- match : ' (?:\s*([a-zA-Z_$][\w$]*))'
106+ match : ' (?:\s*([a-zA-Z_$][\w$]*)\b )'
102107 captures :
103108 ' 1 ' : { name: storage.type.ts }
104109
@@ -139,24 +144,25 @@ repository:
139144
140145 field-declaration :
141146 name : meta.field.declaration.ts
142- begin : ' (?<!\()\s*\b( [a-zA-Z_$][\w$]*)\ s*(\?\s*)?(?=(=|:))'
147+ begin : (?<!\()\s*((?:\b [a-zA-Z_$][\w$]*)|(?:\'[^']*\')|(?:\"[^"]*\"))\ s*(\?\s*)?(?=(=|:))
143148 beginCaptures :
144149 ' 1 ' : { name: variable.ts }
145150 ' 2 ' : { name: keyword.operator.ts }
146- end : ' (?=\}|;|,|(?<!=)\n )|(?<=\})'
151+ end : ' (?=\}|;|,|$ )|(?<=\})'
147152 patterns :
148153 - include : ' #expression'
149154
150155 method-declaration :
151156 name : meta.method.declaration.ts
152- begin : ' \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?(?:(get|set)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
157+ begin : ' \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)? (?:(get|set)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
153158 beginCaptures :
154159 ' 1 ' : { name: storage.modifier.ts }
155160 ' 2 ' : { name: storage.modifier.ts }
156- ' 3 ' : { name: storage.type.property.ts }
157- ' 4 ' : { name: keyword.operator.ts }
158- ' 5 ' : { name: entity.name.function.ts }
159- ' 6 ' : { name: keyword.operator.ts }
161+ ' 3 ' : { name: storage.modifier.ts }
162+ ' 4 ' : { name: storage.type.property.ts }
163+ ' 5 ' : { name: keyword.operator.ts }
164+ ' 6 ' : { name: entity.name.function.ts }
165+ ' 7 ' : { name: keyword.operator.ts }
160166 end : ' (?=\}|;|,)|(?<=\})'
161167 patterns :
162168 - include : ' #comment'
@@ -168,12 +174,15 @@ repository:
168174
169175 method-overload-declaration :
170176 name : meta.method.overload.declaration.ts
171- match : ' \b(?:(public|private|protected)\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
177+ match : ' \b(?:(abstract)\s+)?\b(?:( public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set )\s+)?(?:(new)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
172178 captures :
173179 ' 1 ' : { name: storage.modifier.ts }
174- ' 2 ' : { name: keyword.operator.ts }
175- ' 3 ' : { name: entity.name.function.ts }
176- ' 4 ' : { name: keyword.operator.ts }
180+ ' 2 ' : { name: storage.modifier.ts }
181+ ' 3 ' : { name: storage.modifier.ts }
182+ ' 4 ' : { name: storage.type.property.ts }
183+ ' 5 ' : { name: keyword.operator.ts }
184+ ' 6 ' : { name: entity.name.function.ts }
185+ ' 7 ' : { name: keyword.operator.ts }
177186
178187 indexer-declaration :
179188 name : meta.indexer.declaration.ts
@@ -194,14 +203,15 @@ repository:
194203 match : ([a-zA-Z_$][\w$]*)(?=\:)
195204 captures :
196205 ' 1 ' : { name: variable.parameter.ts}
197-
206+
198207 function-declaration :
199208 name : meta.function.ts
200- begin : \b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s*
209+ begin : \b(?:(export)\s+)?(?:(async)\s+)?( function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s*
201210 beginCaptures :
202211 ' 1 ' : { name: storage.modifier.ts }
203- ' 2 ' : { name: storage.type.function.ts }
204- ' 3 ' : { name: entity.name.function.ts }
212+ ' 2 ' : { name: storage.modifier.ts }
213+ ' 3 ' : { name: storage.type.function.ts }
214+ ' 4 ' : { name: entity.name.function.ts }
205215 end : (?=;|\})|(?<=\})
206216 patterns :
207217 - include : ' #comment'
@@ -228,8 +238,8 @@ repository:
228238 endCaptures :
229239 ' 0 ' : { name: meta.brace.curly.ts }
230240 patterns :
231- - include : ' #expression'
232241 - include : ' #object-member'
242+ - include : ' #expression'
233243
234244 decl-block :
235245 name : meta.decl.block.ts
@@ -313,7 +323,11 @@ repository:
313323 - include : ' #comment'
314324 - include : ' #type'
315325 - include : ' #function-type-parameters'
316-
326+
327+ await-modifier :
328+ name : storage.modifier.ts
329+ match : ' \bawait\b'
330+
317331 type-operator :
318332 name : keyword.operator.type.ts
319333 match : ' [.|]'
@@ -351,7 +365,7 @@ repository:
351365 beginCaptures :
352366 ' 1 ' : { name: entity.name.type.ts }
353367 ' 2 ' : { name: meta.brace.angle.ts }
354- end : ' (?=$)|(>)'
368+ end : ' (?=$)|(>)'
355369 endCaptures :
356370 ' 2 ' : { name: meta.brace.angle.ts }
357371 patterns :
@@ -366,7 +380,7 @@ repository:
366380 ' 1 ' : { name: keyword.operator.ts }
367381 end : (?=$|[,);=])
368382 patterns :
369- - include : ' #expression'
383+ - include : ' #expression'
370384
371385 expression :
372386 name : meta.expression.ts
@@ -382,6 +396,7 @@ repository:
382396 - include : ' #declaration'
383397 - include : ' #cast'
384398 - include : ' #new-expr'
399+ - include : ' #switch-statement'
385400 - include : ' #block'
386401 - include : ' #expression-operator'
387402 - include : ' #relational-operator'
@@ -390,9 +405,42 @@ repository:
390405 - include : ' #assignment-operator'
391406 - include : ' #storage-keyword'
392407 - include : ' #function-call'
393- - include : ' #switch- case'
408+ - include : ' #case-clause '
394409 - include : ' #control-statement'
395-
410+
411+ switch-expression :
412+ name : switch-expression.expr.ts
413+ begin : \b(switch)\b\s*\(
414+ beginCaptures :
415+ ' 1 ' : { name: keyword.operator.ts }
416+ end : \)
417+ patterns :
418+ - include : ' #expression'
419+
420+ switch-block :
421+ name : switch-block.expr.ts
422+ begin : ' {'
423+ end : (?=\})
424+ patterns :
425+ - include : ' #expression'
426+
427+ case-clause :
428+ name : case-clause.expr.ts
429+ begin : ' (?<!\.)\b(case|default)\b'
430+ beginCaptures :
431+ ' 1 ' : { name: keyword.control.ts }
432+ end : ' :'
433+ patterns :
434+ - include : ' #expression'
435+
436+ switch-statement :
437+ name : switch-statement.expr.ts
438+ begin : (?=\bswitch\b\s*\()
439+ end : ' }'
440+ patterns :
441+ - include : ' #switch-expression'
442+ - include : ' #switch-block'
443+
396444 for-in-simple :
397445 name : forin.expr.ts
398446 match : (?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b
@@ -403,16 +451,17 @@ repository:
403451 function-call :
404452 name : functioncall.expr.ts
405453 patterns :
454+ - include : ' #await-modifier'
406455 - include : ' #type-parameters'
407456 - include : ' #paren-expression'
408457
409458 cast :
410459 name : cast.expr.ts
411- # To differentiate a cast vs a relational <, this regexp tries to use the surrounding context
412- # If < is preceeded by 'return', 'throw', 'yield' its most likely a type assertion
413- # An '=', '(', ',', ':', or '>' character followed by '<' is likely a type assertion, as otherwise its a syntax error
414- # '<=' and '<<=' are definately not type assertions, as they are assignment operators.
415- begin : ' (?:(?<=return|throw|yield|[=(,:>]))\s*(<)(?!<?\=)'
460+ # We need to differentiate between the relational '<' operator and the beginning of a type assertion/cast using the surrounding context.
461+ # If '<' is preceeded by 'return', 'throw', 'yield', or 'await', it's most likely a type assertion
462+ # If '=', '(', ',', ':', or '>' are followed by a '<', it is also likely a type assertion as otherwise it would be a syntax error
463+ # '<=' and '<<=' are cannot be type assertions, as they are assignment operators.
464+ begin : ' (?:(?<=return|throw|yield|await| [=(,:>]))\s*(<)(?!<?\=)'
416465 beginCaptures :
417466 ' 1 ' : { name: meta.brace.angle.ts }
418467 end : ' >'
@@ -441,7 +490,7 @@ repository:
441490
442491 expression-operator :
443492 name : keyword.operator.ts
444- match : =>|\b(delete|export|import|in|instanceof|module|namespace| new|typeof|void)\b
493+ match : =>|\b(delete|export|import|from| in|instanceof|new|typeof|void|as )\b
445494
446495 arithmetic-operator :
447496 name : keyword.operator.arithmetic.ts
@@ -457,11 +506,11 @@ repository:
457506
458507 logic-operator :
459508 name : keyword.operator.arithmetic.ts
460- match : \!|&|~|\||&&|\|\|
509+ match : \!|&|~|\^|\ ||&&|\|\|
461510
462511 storage-keyword :
463512 name : storage.type.ts
464- match : \b(number|boolean|string|any|var|let|function|const)\b
513+ match : \b(number|boolean|string|any|var|let|function|const|module|namespace )\b
465514
466515 paren-expression :
467516 begin : \(
@@ -476,14 +525,14 @@ repository:
476525 qstring-double :
477526 name : string.double.ts
478527 begin : ' "'
479- end : ' "|(?= $)'
528+ end : ' "|(?:[^\\\n] $)'
480529 patterns :
481530 - include : ' #string-character-escape'
482531
483532 qstring-single :
484533 name : string.single.ts
485534 begin : " '"
486- end : " '|(?=$) "
535+ end : \ '|(?:[^\\\n]$)
487536 patterns :
488537 - include : ' #string-character-escape'
489538
@@ -556,7 +605,7 @@ repository:
556605
557606 comment-line :
558607 name : comment.line.ts
559- match : (//).*$
608+ match : (//).*$\n?
560609
561610 literal :
562611 name : literal.ts
@@ -580,7 +629,7 @@ repository:
580629 - include : ' #expression'
581630
582631 numeric-literal :
583- name : constant.numeric.ts
632+ name : constant.numeric.ts
584633 match : \b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b
585634
586635 boolean-literal :
@@ -590,19 +639,19 @@ repository:
590639 null-literal :
591640 name : constant.language.null.ts
592641 match : \b(null)\b
593-
642+
594643 this-literal :
595644 name : constant.language.this.ts
596645 match : \b(this)\b
597-
646+
598647 undefined-literal :
599648 name : constant.language.ts
600649 match : \b(undefined)\b
601650
602651 access-modifier :
603652 name : storage.modifier.ts
604653 match : \b(public|protected|private)\b
605-
654+
606655 static-modifier :
607656 name : keyword.other.ts
608657 match : \b(static)\b
@@ -611,4 +660,4 @@ repository:
611660 name : storage.type.property.ts
612661 match : \b(get|set)\b
613662
614- ...
663+ ...
0 commit comments