Skip to content

Commit 2d15a59

Browse files
committed
Some rearranging for type-predicate and typeof operator
1 parent bbaffdc commit 2d15a59

File tree

4 files changed

+90
-38
lines changed

4 files changed

+90
-38
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,19 @@ repository:
702702
'0': { name: punctuation.definition.block.ts }
703703
patterns:
704704
- include: '#type-object-members'
705+
- include: '#type-predicate-operator'
705706
- include: '#type'
706707

708+
type-predicate-operator:
709+
name: keyword.operator.is.ts
710+
match: (?<!\.|\$)\bis\b(?!\$)
711+
707712
type-annotation:
708713
name: meta.type.annotation.ts
709714
begin: ":"
710715
end: (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)
711716
patterns:
712717
- include: '#comment'
713-
- include: '#expression-operator'
714718
- include: '#type'
715719

716720
type:
@@ -720,6 +724,7 @@ repository:
720724
- include: '#string'
721725
- include: '#type-primitive'
722726
- include: '#type-builtin-literals'
727+
- include: '#typeof-operator'
723728
- include: '#type-parameters'
724729
- include: '#type-tuple'
725730
- include: '#type-object'
@@ -791,6 +796,7 @@ repository:
791796
'0': { name: punctuation.definition.block.ts }
792797
patterns:
793798
- include: '#type-object-members'
799+
- include: '#type-predicate-operator'
794800
- include: '#type'
795801

796802
type-tuple:
@@ -956,14 +962,15 @@ repository:
956962
match: (?<!\.|\$)\binstanceof\b(?!\$)
957963
- name: keyword.operator.new.ts
958964
match: (?<!\.|\$)\bnew\b(?!\$)
959-
- name: keyword.operator.typeof.ts
960-
match: (?<!\.|\$)\btypeof\b(?!\$)
965+
- include: '#typeof-operator'
961966
- name: keyword.operator.void.ts
962967
match: (?<!\.|\$)\bvoid\b(?!\$)
963968
- name: keyword.control.as.ts
964969
match: (?<!\.|\$)\bas\b(?!\$)
965-
- name: keyword.operator.is.ts
966-
match: (?<!\.|\$)\bis\b(?!\$)
970+
971+
typeof-operator:
972+
name: keyword.operator.typeof.ts
973+
match: (?<!\.|\$)\btypeof\b(?!\$)
967974

968975
operators:
969976
patterns:
@@ -1024,6 +1031,7 @@ repository:
10241031
end: (?<!:)((?=$)|(?==>|;|//))
10251032
patterns:
10261033
# TODO: handle the fn and constructor type specifically.
1034+
- include: '#type-predicate-operator'
10271035
- include: '#type'
10281036

10291037
paren-expression:

TypeScript.tmLanguage

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@
242242
<string>meta.return.type.arrow.ts</string>
243243
<key>patterns</key>
244244
<array>
245+
<dict>
246+
<key>include</key>
247+
<string>#type-predicate-operator</string>
248+
</dict>
245249
<dict>
246250
<key>include</key>
247251
<string>#type</string>
@@ -1269,10 +1273,8 @@
12691273
<string>keyword.operator.new.ts</string>
12701274
</dict>
12711275
<dict>
1272-
<key>match</key>
1273-
<string>(?&lt;!\.|\$)\btypeof\b(?!\$)</string>
1274-
<key>name</key>
1275-
<string>keyword.operator.typeof.ts</string>
1276+
<key>include</key>
1277+
<string>#typeof-operator</string>
12761278
</dict>
12771279
<dict>
12781280
<key>match</key>
@@ -1286,12 +1288,6 @@
12861288
<key>name</key>
12871289
<string>keyword.control.as.ts</string>
12881290
</dict>
1289-
<dict>
1290-
<key>match</key>
1291-
<string>(?&lt;!\.|\$)\bis\b(?!\$)</string>
1292-
<key>name</key>
1293-
<string>keyword.operator.is.ts</string>
1294-
</dict>
12951291
</array>
12961292
</dict>
12971293
<key>field-declaration</key>
@@ -3108,6 +3104,10 @@
31083104
</dict>
31093105
</array>
31103106
</dict>
3107+
<dict>
3108+
<key>include</key>
3109+
<string>#type-predicate-operator</string>
3110+
</dict>
31113111
<dict>
31123112
<key>include</key>
31133113
<string>#type</string>
@@ -3448,6 +3448,10 @@
34483448
<key>include</key>
34493449
<string>#type-builtin-literals</string>
34503450
</dict>
3451+
<dict>
3452+
<key>include</key>
3453+
<string>#typeof-operator</string>
3454+
</dict>
34513455
<dict>
34523456
<key>include</key>
34533457
<string>#type-parameters</string>
@@ -3492,10 +3496,6 @@
34923496
<key>include</key>
34933497
<string>#comment</string>
34943498
</dict>
3495-
<dict>
3496-
<key>include</key>
3497-
<string>#expression-operator</string>
3498-
</dict>
34993499
<dict>
35003500
<key>include</key>
35013501
<string>#type</string>
@@ -3610,6 +3610,10 @@
36103610
</dict>
36113611
</array>
36123612
</dict>
3613+
<dict>
3614+
<key>include</key>
3615+
<string>#type-predicate-operator</string>
3616+
</dict>
36133617
<dict>
36143618
<key>include</key>
36153619
<string>#type</string>
@@ -3793,6 +3797,13 @@
37933797
</dict>
37943798
</array>
37953799
</dict>
3800+
<key>type-predicate-operator</key>
3801+
<dict>
3802+
<key>match</key>
3803+
<string>(?&lt;!\.|\$)\bis\b(?!\$)</string>
3804+
<key>name</key>
3805+
<string>keyword.operator.is.ts</string>
3806+
</dict>
37963807
<key>type-primitive</key>
37973808
<dict>
37983809
<key>match</key>
@@ -3832,6 +3843,13 @@
38323843
</dict>
38333844
</array>
38343845
</dict>
3846+
<key>typeof-operator</key>
3847+
<dict>
3848+
<key>match</key>
3849+
<string>(?&lt;!\.|\$)\btypeof\b(?!\$)</string>
3850+
<key>name</key>
3851+
<string>keyword.operator.typeof.ts</string>
3852+
</dict>
38353853
<key>undefined-literal</key>
38363854
<dict>
38373855
<key>match</key>

TypeScriptReact.YAML-tmLanguage

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,15 +706,19 @@ repository:
706706
'0': { name: punctuation.definition.block.tsx }
707707
patterns:
708708
- include: '#type-object-members'
709+
- include: '#type-predicate-operator'
709710
- include: '#type'
710711

712+
type-predicate-operator:
713+
name: keyword.operator.is.tsx
714+
match: (?<!\.|\$)\bis\b(?!\$)
715+
711716
type-annotation:
712717
name: meta.type.annotation.tsx
713718
begin: ":"
714719
end: (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)
715720
patterns:
716721
- include: '#comment'
717-
- include: '#expression-operator'
718722
- include: '#type'
719723

720724
type:
@@ -724,6 +728,7 @@ repository:
724728
- include: '#string'
725729
- include: '#type-primitive'
726730
- include: '#type-builtin-literals'
731+
- include: '#typeof-operator'
727732
- include: '#type-parameters'
728733
- include: '#type-tuple'
729734
- include: '#type-object'
@@ -795,6 +800,7 @@ repository:
795800
'0': { name: punctuation.definition.block.tsx }
796801
patterns:
797802
- include: '#type-object-members'
803+
- include: '#type-predicate-operator'
798804
- include: '#type'
799805

800806
type-tuple:
@@ -945,14 +951,15 @@ repository:
945951
match: (?<!\.|\$)\binstanceof\b(?!\$)
946952
- name: keyword.operator.new.tsx
947953
match: (?<!\.|\$)\bnew\b(?!\$)
948-
- name: keyword.operator.typeof.tsx
949-
match: (?<!\.|\$)\btypeof\b(?!\$)
954+
- include: '#typeof-operator'
950955
- name: keyword.operator.void.tsx
951956
match: (?<!\.|\$)\bvoid\b(?!\$)
952957
- name: keyword.control.as.tsx
953958
match: (?<!\.|\$)\bas\b(?!\$)
954-
- name: keyword.operator.is.tsx
955-
match: (?<!\.|\$)\bis\b(?!\$)
959+
960+
typeof-operator:
961+
name: keyword.operator.typeof.tsx
962+
match: (?<!\.|\$)\btypeof\b(?!\$)
956963

957964
operators:
958965
patterns:
@@ -1013,6 +1020,7 @@ repository:
10131020
end: (?<!:)((?=$)|(?==>|;|//))
10141021
patterns:
10151022
# TODO: handle the fn and constructor type specifically.
1023+
- include: '#type-predicate-operator'
10161024
- include: '#type'
10171025

10181026
paren-expression:

TypeScriptReact.tmLanguage

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@
242242
<string>meta.return.type.arrow.tsx</string>
243243
<key>patterns</key>
244244
<array>
245+
<dict>
246+
<key>include</key>
247+
<string>#type-predicate-operator</string>
248+
</dict>
245249
<dict>
246250
<key>include</key>
247251
<string>#type</string>
@@ -1237,10 +1241,8 @@
12371241
<string>keyword.operator.new.tsx</string>
12381242
</dict>
12391243
<dict>
1240-
<key>match</key>
1241-
<string>(?&lt;!\.|\$)\btypeof\b(?!\$)</string>
1242-
<key>name</key>
1243-
<string>keyword.operator.typeof.tsx</string>
1244+
<key>include</key>
1245+
<string>#typeof-operator</string>
12441246
</dict>
12451247
<dict>
12461248
<key>match</key>
@@ -1254,12 +1256,6 @@
12541256
<key>name</key>
12551257
<string>keyword.control.as.tsx</string>
12561258
</dict>
1257-
<dict>
1258-
<key>match</key>
1259-
<string>(?&lt;!\.|\$)\bis\b(?!\$)</string>
1260-
<key>name</key>
1261-
<string>keyword.operator.is.tsx</string>
1262-
</dict>
12631259
</array>
12641260
</dict>
12651261
<key>field-declaration</key>
@@ -3494,6 +3490,10 @@
34943490
</dict>
34953491
</array>
34963492
</dict>
3493+
<dict>
3494+
<key>include</key>
3495+
<string>#type-predicate-operator</string>
3496+
</dict>
34973497
<dict>
34983498
<key>include</key>
34993499
<string>#type</string>
@@ -3838,6 +3838,10 @@
38383838
<key>include</key>
38393839
<string>#type-builtin-literals</string>
38403840
</dict>
3841+
<dict>
3842+
<key>include</key>
3843+
<string>#typeof-operator</string>
3844+
</dict>
38413845
<dict>
38423846
<key>include</key>
38433847
<string>#type-parameters</string>
@@ -3882,10 +3886,6 @@
38823886
<key>include</key>
38833887
<string>#comment</string>
38843888
</dict>
3885-
<dict>
3886-
<key>include</key>
3887-
<string>#expression-operator</string>
3888-
</dict>
38893889
<dict>
38903890
<key>include</key>
38913891
<string>#type</string>
@@ -4000,6 +4000,10 @@
40004000
</dict>
40014001
</array>
40024002
</dict>
4003+
<dict>
4004+
<key>include</key>
4005+
<string>#type-predicate-operator</string>
4006+
</dict>
40034007
<dict>
40044008
<key>include</key>
40054009
<string>#type</string>
@@ -4183,6 +4187,13 @@
41834187
</dict>
41844188
</array>
41854189
</dict>
4190+
<key>type-predicate-operator</key>
4191+
<dict>
4192+
<key>match</key>
4193+
<string>(?&lt;!\.|\$)\bis\b(?!\$)</string>
4194+
<key>name</key>
4195+
<string>keyword.operator.is.tsx</string>
4196+
</dict>
41864197
<key>type-primitive</key>
41874198
<dict>
41884199
<key>match</key>
@@ -4222,6 +4233,13 @@
42224233
</dict>
42234234
</array>
42244235
</dict>
4236+
<key>typeof-operator</key>
4237+
<dict>
4238+
<key>match</key>
4239+
<string>(?&lt;!\.|\$)\btypeof\b(?!\$)</string>
4240+
<key>name</key>
4241+
<string>keyword.operator.typeof.tsx</string>
4242+
</dict>
42254243
<key>undefined-literal</key>
42264244
<dict>
42274245
<key>match</key>

0 commit comments

Comments
 (0)