Skip to content

Commit 2ea303c

Browse files
committed
Handle '|' and '&' operator in function return type when they are followed by object type
Fixes #427
1 parent b68820e commit 2ea303c

File tree

5 files changed

+210
-15
lines changed

5 files changed

+210
-15
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,12 @@ repository:
836836
begin: (?<=\))\s*(:)
837837
beginCaptures:
838838
'1': { name: keyword.operator.type.annotation.ts }
839-
end: (?<!:)((?=$)|(?=[{};,]|//))
839+
end: (?<![:|&])((?=$)|(?=[{};,]|//))
840840
patterns:
841841
- include: '#comment'
842842
# Handle returning of object type specifically here so as to not confuse it with the start of function block
843843
- name: meta.object.type.ts
844-
begin: (?<=:)\s*(\{)
844+
begin: (?<=[:|&])\s*(\{)
845845
beginCaptures:
846846
'1': { name: punctuation.definition.block.ts }
847847
end: \}
@@ -970,12 +970,12 @@ repository:
970970
begin: '=>'
971971
beginCaptures:
972972
'0': { name: storage.type.function.arrow.ts }
973-
end: (?<!=>)(?=[,\]\)\{\}=;>]|//|$)
973+
end: (?<!=>)(?<![|&])(?=[,\]\)\{\}=;>]|//|$)
974974
patterns:
975975
- include: '#comment'
976976
# Handle returning of object type specifically here so as to not confuse it with the start of function block
977977
- name: meta.object.type.ts
978-
begin: (?<==>)\s*(\{)
978+
begin: (?:(?<==>)|(?<=[|&]))\s*(\{)
979979
beginCaptures:
980980
'1': { name: punctuation.definition.block.ts }
981981
end: \}
@@ -1663,7 +1663,7 @@ repository:
16631663
# TODO: handle the fn and constructor type specifically.
16641664
# Handle returning of object type specifically here so as to not confuse it with the start of function block
16651665
- name: meta.object.type.ts
1666-
begin: (?<=:)\s*(\{)
1666+
begin: (?<=[:|&])\s*(\{)
16671667
beginCaptures:
16681668
'1': { name: punctuation.definition.block.ts }
16691669
end: \}

TypeScript.tmLanguage

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@
25812581
</dict>
25822582
</dict>
25832583
<key>end</key>
2584-
<string>(?&lt;!:)((?=$)|(?=[{};,]|//))</string>
2584+
<string>(?&lt;![:|&amp;])((?=$)|(?=[{};,]|//))</string>
25852585
<key>patterns</key>
25862586
<array>
25872587
<dict>
@@ -2592,7 +2592,7 @@
25922592
<key>name</key>
25932593
<string>meta.object.type.ts</string>
25942594
<key>begin</key>
2595-
<string>(?&lt;=:)\s*(\{)</string>
2595+
<string>(?&lt;=[:|&amp;])\s*(\{)</string>
25962596
<key>beginCaptures</key>
25972597
<dict>
25982598
<key>1</key>
@@ -2936,7 +2936,7 @@
29362936
</dict>
29372937
</dict>
29382938
<key>end</key>
2939-
<string>(?&lt;!=&gt;)(?=[,\]\)\{\}=;&gt;]|//|$)</string>
2939+
<string>(?&lt;!=&gt;)(?&lt;![|&amp;])(?=[,\]\)\{\}=;&gt;]|//|$)</string>
29402940
<key>patterns</key>
29412941
<array>
29422942
<dict>
@@ -2947,7 +2947,7 @@
29472947
<key>name</key>
29482948
<string>meta.object.type.ts</string>
29492949
<key>begin</key>
2950-
<string>(?&lt;==&gt;)\s*(\{)</string>
2950+
<string>(?:(?&lt;==&gt;)|(?&lt;=[|&amp;]))\s*(\{)</string>
29512951
<key>beginCaptures</key>
29522952
<dict>
29532953
<key>1</key>
@@ -4549,7 +4549,7 @@
45494549
<key>name</key>
45504550
<string>meta.object.type.ts</string>
45514551
<key>begin</key>
4552-
<string>(?&lt;=:)\s*(\{)</string>
4552+
<string>(?&lt;=[:|&amp;])\s*(\{)</string>
45534553
<key>beginCaptures</key>
45544554
<dict>
45554555
<key>1</key>

TypeScriptReact.tmLanguage

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@
25852585
</dict>
25862586
</dict>
25872587
<key>end</key>
2588-
<string>(?&lt;!:)((?=$)|(?=[{};,]|//))</string>
2588+
<string>(?&lt;![:|&amp;])((?=$)|(?=[{};,]|//))</string>
25892589
<key>patterns</key>
25902590
<array>
25912591
<dict>
@@ -2596,7 +2596,7 @@
25962596
<key>name</key>
25972597
<string>meta.object.type.tsx</string>
25982598
<key>begin</key>
2599-
<string>(?&lt;=:)\s*(\{)</string>
2599+
<string>(?&lt;=[:|&amp;])\s*(\{)</string>
26002600
<key>beginCaptures</key>
26012601
<dict>
26022602
<key>1</key>
@@ -2940,7 +2940,7 @@
29402940
</dict>
29412941
</dict>
29422942
<key>end</key>
2943-
<string>(?&lt;!=&gt;)(?=[,\]\)\{\}=;&gt;]|//|$)</string>
2943+
<string>(?&lt;!=&gt;)(?&lt;![|&amp;])(?=[,\]\)\{\}=;&gt;]|//|$)</string>
29442944
<key>patterns</key>
29452945
<array>
29462946
<dict>
@@ -2951,7 +2951,7 @@
29512951
<key>name</key>
29522952
<string>meta.object.type.tsx</string>
29532953
<key>begin</key>
2954-
<string>(?&lt;==&gt;)\s*(\{)</string>
2954+
<string>(?:(?&lt;==&gt;)|(?&lt;=[|&amp;]))\s*(\{)</string>
29552955
<key>beginCaptures</key>
29562956
<dict>
29572957
<key>1</key>
@@ -4495,7 +4495,7 @@
44954495
<key>name</key>
44964496
<string>meta.object.type.tsx</string>
44974497
<key>begin</key>
4498-
<string>(?&lt;=:)\s*(\{)</string>
4498+
<string>(?&lt;=[:|&amp;])\s*(\{)</string>
44994499
<key>beginCaptures</key>
45004500
<dict>
45014501
<key>1</key>

0 commit comments

Comments
 (0)