@@ -16,33 +16,45 @@ variables:
16
16
nonIdentifierPropertyName : ' {{quotedStrings}}|(\[([^\[\]]|\[[^\[\]]*\])+\])'
17
17
propertyName : (({{identifier}})|{{nonIdentifierPropertyName}})
18
18
constantVar : ({{constantIdentifier}})(?![_$[:alnum:]])
19
+ nonPropertyLookBehind : ' [^\._$[:alnum:]]'
20
+ lookBehindReturn : ' ^return|{{nonPropertyLookBehind}}return'
21
+ lookBehindThrow : ' ^throw|{{nonPropertyLookBehind}}throw'
22
+ lookBehindYield : ' ^yield|{{nonPropertyLookBehind}}yield'
23
+ lookBehindAwait : ' ^await|{{nonPropertyLookBehind}}await'
24
+ lookBehindDefault : ' ^default|{{nonPropertyLookBehind}}default'
25
+ lookBehindIn : ' ^in|{{nonPropertyLookBehind}}in'
26
+ lookBehindOf : ' ^of|{{nonPropertyLookBehind}}of'
27
+ lookBehindTypeof : ' ^typeof|{{nonPropertyLookBehind}}typeof'
28
+ lookBehindCase : ' ^case|{{nonPropertyLookBehind}}case'
19
29
matchingParenthesis : (\([^\(\)]*\))
30
+ matchingBraces : (\{[^\{\}]*\})
31
+ matchingBrackets : (\[[^\[\]]*\])
20
32
# Identifier start | matching braces | matching parenthesis | matching square brackets
21
- typeParamersStart : ([_$[:alpha:]]|(\{[^\{\}]*\}) |{{matchingParenthesis}}|(\[[^\[\]]*\]) )
33
+ typeParamersStart : ([_$[:alpha:]]|{{matchingBraces}} |{{matchingParenthesis}}|{{matchingBrackets}} )
22
34
typeParameters : (<\s*{{typeParamersStart}}([^=<>]|=[^<]|\<\s*{{typeParamersStart}}([^=<>]|=[^<])*\>)*>\s*)
23
35
# Identifier start | matching braces | matching parenthesis | matching square brackets | matching strings
24
36
typeArgumentsStart : ({{typeParamersStart}}|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))
25
- typeArgumentsInnerExpressionPart : ' [^<>\(]|{{matchingParenthesis}}'
26
- typeArguments : (<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}}|\<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}})*\>)*>\s*)
37
+ typeArgumentsInnerExpressionPart : ' [^<>\(]|{{matchingParenthesis}}|(?<==)\> '
38
+ typeArguments : (<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}}|\<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}})*(?!=) \>)*(?!=) >\s*)
27
39
functionCallLookup : \s*(\?\.\s*)?{{typeArguments}}?\(
28
40
arrowLookup : |-
29
41
# sure shot arrow functions even if => is on new line
30
42
(
31
43
[(]\s*
32
44
(
33
- ([)]\s*:) | # ():
34
- ((\.\.\.\s*)?{{identifier}}\s*:) # [(]param: | [(]...param:
45
+ ([)]\s*:) | # ():
46
+ ((\.\.\.\s*)?{{identifier}}\s*:) # [(]param: | [(]...param:
35
47
)
36
48
) |
37
49
(
38
- [<]\s*{{identifier}}\s+extends\s*[^=>] # < typeparam extends
50
+ [<]\s*{{identifier}}\s+extends\s*[^=>] # < typeparam extends
39
51
) |
40
52
# arrow function possible to detect only with => on same line
41
53
(
42
- {{typeParameters}}? # typeparameters
43
- \(\s*([_$[:alpha:]\{\[] ([^()]|\((\s*[^()] *)?\))*)?\) # parameteres
44
- (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type
45
- \s*=> # arrow operator
54
+ {{typeParameters}}? # typeparameters
55
+ \(\s*(( [_$[:alpha:]]|{{matchingBraces}}|{{matchingBrackets}}) ([^()]|{{matchingParenthesis}}) *)?\) # parameters
56
+ (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type
57
+ \s*=> # arrow operator
46
58
)
47
59
functionOrArrowLookup : |-
48
60
\s*(
@@ -70,7 +82,8 @@ variables:
70
82
([)]\s*=>)
71
83
))
72
84
))
73
- ))
85
+ )) |
86
+ (:\s*(=>|{{matchingParenthesis}}|(<[^<>]*>)|[^<>(),=])+={{functionOrArrowLookup}})
74
87
75
88
patterns :
76
89
- include : ' #directives'
@@ -226,14 +239,14 @@ repository:
226
239
destructuring-variable :
227
240
patterns :
228
241
- name : meta.object-binding-pattern-variable.ts
229
- begin : (?<!=|:|of|in )\s*(?=\{)
242
+ begin : (?<!=|:|{{lookBehindOf}}|{{lookBehindIn}} )\s*(?=\{)
230
243
end : (?=$|^|[;,=}]|(\s+(of|in)\s+))
231
244
patterns :
232
245
- include : ' #object-binding-pattern'
233
246
- include : ' #type-annotation'
234
247
- include : ' #comment'
235
248
- name : meta.array-binding-pattern-variable.ts
236
- begin : (?<!=|:|of|in )\s*(?=\[)
249
+ begin : (?<!=|:|{{lookBehindOf}}|{{lookBehindIn}} )\s*(?=\[)
237
250
end : (?=$|^|[;,=}]|(\s+(of|in)\s+))
238
251
patterns :
239
252
- include : ' #array-binding-pattern'
@@ -886,13 +899,14 @@ repository:
886
899
patterns :
887
900
- include : ' #comment'
888
901
# (default|*|name) as alias
889
- - match : ' {{startOfIdentifier}}(?:(\bdefault)|(\*)|(\b{{identifier}}))\s+(as)\s+(\ b{{identifier}})'
902
+ - match : ' {{startOfIdentifier}}(?:(\bdefault)|(\*)|(\b{{identifier}}))\s+(as)\s+(?:(\bdefault{{endOfIdentifier}})|(\ b{{identifier}}) )'
890
903
captures :
891
904
' 1 ' : { name: keyword.control.default.ts }
892
905
' 2 ' : { name: constant.language.import-export-all.ts }
893
906
' 3 ' : { name: variable.other.readwrite.ts }
894
907
' 4 ' : { name: keyword.control.as.ts }
895
- ' 5 ' : { name: variable.other.readwrite.alias.ts }
908
+ ' 5 ' : { name: keyword.control.default.ts }
909
+ ' 6 ' : { name: variable.other.readwrite.alias.ts }
896
910
- include : ' #punctuation-comma'
897
911
- name : constant.language.import-export-all.ts
898
912
match : \*
@@ -965,7 +979,7 @@ repository:
965
979
# object literals
966
980
after-operator-block-as-object-literal :
967
981
name : meta.objectliteral.ts
968
- begin : (?<=[=(,\[?+!]|await|return|yield|throw|in|of|typeof |&&|\|\||\*)\s*(\{)
982
+ begin : (?<=[=(,\[?+!]|{{lookBehindAwait}}|{{lookBehindReturn}}|{{lookBehindYield}}|{{lookBehindThrow}}|{{lookBehindIn}}|{{lookBehindOf}}|{{lookBehindTypeof}} |&&|\|\||\*)\s*(\{)
969
983
beginCaptures :
970
984
' 1 ' : { name: punctuation.definition.block.ts }
971
985
end : \}
@@ -1088,7 +1102,7 @@ repository:
1088
1102
begin : ' {{startOfIdentifier}}(new){{endOfIdentifier}}'
1089
1103
beginCaptures :
1090
1104
' 1 ' : { name: keyword.operator.new.ts }
1091
- end : (?<=\))|(?=[;),}\]]|$|({{startOfIdentifier}}new{{endOfIdentifier}})|({{startOfIdentifier}}function((\s+{{identifier}})|(\s*[\(]))))
1105
+ end : (?<=\))|(?=[;),}\]: ]|$|({{startOfIdentifier}}new{{endOfIdentifier}})|({{startOfIdentifier}}function((\s+{{identifier}})|(\s*[\(]))))
1092
1106
patterns :
1093
1107
- include : ' #paren-expression'
1094
1108
- include : ' #class-declaration'
@@ -1113,7 +1127,7 @@ repository:
1113
1127
# If '<' is preceeded by 'return', 'throw', 'yield', or 'await', it's most likely a type assertion
1114
1128
# If '=', '(', ',', ':', or '>' are followed by a '<', it is also likely a type assertion as otherwise it would be a syntax error
1115
1129
# '<=' and '<<=' are cannot be type assertions, as they are assignment operators.
1116
- begin : (?:(?<=return|throw|yield|await|default |[=(,:>*?\&\|\^]|[^_$[:alnum:]](?:\+\+|\-\-)|[^\+]\+|[^\-]\-))\s*(<)(?!<?\=)
1130
+ begin : (?:(?<={{lookBehindReturn}}|{{lookBehindThrow}}|{{lookBehindYield}}|{{lookBehindAwait}}|{{lookBehindDefault}} |[=(,:>*?\&\|\^]|[^_$[:alnum:]](?:\+\+|\-\-)|[^\+]\+|[^\-]\-))\s*(<)(?!<?\=)
1117
1131
beginCaptures :
1118
1132
' 1 ' : { name: meta.brace.angle.ts }
1119
1133
end : (\>)\s*
@@ -1221,25 +1235,28 @@ repository:
1221
1235
- include : ' #expression'
1222
1236
- include : ' #punctuation-comma'
1223
1237
1238
+ # With respect to seperators, we allow mroe than is syntacically valid below
1239
+ # (multiple consecutive and trailing ones are errors), to be more graceful
1240
+ # when the code contains errors
1224
1241
numeric-literal :
1225
1242
patterns :
1226
1243
- name : constant.numeric.hex.ts
1227
- match : \b(?<!\$)0(x|X)[0-9a-fA-F]+ \b(?!\$)
1244
+ match : \b(?<!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]* \b(?!\$)
1228
1245
- name : constant.numeric.binary.ts
1229
- match : \b(?<!\$)0(b|B)[01]+ \b(?!\$)
1246
+ match : \b(?<!\$)0(b|B)[01][01_]* \b(?!\$)
1230
1247
- name : constant.numeric.octal.ts
1231
- match : \b(?<!\$)0(o|O)?[0-7]+ \b(?!\$)
1248
+ match : \b(?<!\$)0(o|O)?[0-7][0-7_]* \b(?!\$)
1232
1249
- match : |-
1233
1250
(?x)
1234
1251
(?<!\$)(?:
1235
- (?:\b[0-9]+ (\.)[0-9]+[ eE][+-]?[0-9]+ \b)| # 1.1E+3
1236
- (?:\b[0-9]+ (\.)[eE][+-]?[0-9]+ \b)| # 1.E+3
1237
- (?:\B(\.)[0-9]+[ eE][+-]?[0-9]+ \b)| # .1E+3
1238
- (?:\b[0-9]+[ eE][+-]?[0-9]+ \b)| # 1E+3
1239
- (?:\b[0-9]+ (\.)[0-9]+ \b)| # 1.1
1240
- (?:\b[0-9]+ (\.)\B)| # 1.
1241
- (?:\B(\.)[0-9]+ \b)| # .1
1242
- (?:\b[0-9]+ \b(?!\.)) # 1
1252
+ (?:\b[0-9][0-9_]* (\.)[0-9][0-9_]*[ eE][+-]?[0-9][0-9_]* \b)| # 1.1E+3
1253
+ (?:\b[0-9][0-9_]* (\.)[eE][+-]?[0-9][0-9_]* \b)| # 1.E+3
1254
+ (?:\B(\.)[0-9][0-9_]*[ eE][+-]?[0-9][0-9_]* \b)| # .1E+3
1255
+ (?:\b[0-9][0-9_]*[ eE][+-]?[0-9][0-9_]* \b)| # 1E+3
1256
+ (?:\b[0-9][0-9_]* (\.)[0-9][0-9_]* \b)| # 1.1
1257
+ (?:\b[0-9][0-9_]* (\.)\B)| # 1.
1258
+ (?:\B(\.)[0-9][0-9_]* \b)| # .1
1259
+ (?:\b[0-9][0-9_]* \b(?!\.)) # 1
1243
1260
)(?!\$)
1244
1261
captures:
1245
1262
'0': {name: constant.numeric.decimal.ts}
@@ -1707,6 +1724,7 @@ repository:
1707
1724
- include : ' #type-parameters'
1708
1725
- include : ' #type-tuple'
1709
1726
- include : ' #type-object'
1727
+ - include : ' #type-conditional'
1710
1728
- include : ' #type-operators'
1711
1729
- include : ' #type-fn-type-parameters'
1712
1730
- include : ' #type-paren-or-function-parameters'
@@ -1758,6 +1776,13 @@ repository:
1758
1776
- include : ' #punctuation-semicolon'
1759
1777
- include : ' #type'
1760
1778
1779
+ # conditional type
1780
+ type-conditional :
1781
+ match : ' {{startOfIdentifier}}({{identifier}})\s+(extends)\s+'
1782
+ captures :
1783
+ ' 1 ' : { name: entity.name.type.ts }
1784
+ ' 2 ' : { name: storage.modifier.ts }
1785
+
1761
1786
# Parenthesis can contain either types and function parameters
1762
1787
# (number | string) or (param: number, param2: string)
1763
1788
# and it can be nested, for example
@@ -1856,6 +1881,10 @@ repository:
1856
1881
end : (?=\S)
1857
1882
- name : keyword.operator.expression.keyof.ts
1858
1883
match : ' {{startOfIdentifier}}keyof{{endOfIdentifier}}'
1884
+ - name : keyword.operator.ternary.ts
1885
+ match : (\?|\:)
1886
+ - name : keyword.operator.expression.infer.ts
1887
+ match : ' {{startOfIdentifier}}infer(?=\s+[_$[:alpha:]])'
1859
1888
1860
1889
type-predicate-operator :
1861
1890
name : keyword.operator.expression.is.ts
@@ -1951,7 +1980,7 @@ repository:
1951
1980
regex :
1952
1981
patterns :
1953
1982
- name : string.regexp.ts
1954
- begin : (?<=[=(:,\[?+!]|return|case |=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
1983
+ begin : (?<=[=(:,\[?+!]|{{lookBehindReturn}}|{{lookBehindCase}} |=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
1955
1984
beginCaptures :
1956
1985
' 1 ' : {name: punctuation.definition.string.begin.ts}
1957
1986
end : (/)([gimuy]*)
0 commit comments