Skip to content

Commit 4b6badf

Browse files
committed
Arrow functions
1 parent e038ac8 commit 4b6badf

27 files changed

+1305
-86
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,13 @@ repository:
167167
- include: '#literal'
168168
- include: '#function-declaration'
169169
- include: '#class-or-interface-declaration'
170+
- include: '#cast'
171+
- include: '#arrow-function'
170172
- include: '#paren-expression'
171173
- include: '#ternary-expression'
172-
- include: '#cast'
173174
- include: '#new-expr'
174-
- include: '#arrow-body'
175175
- include: '#object-literal'
176176
- include: '#expression-operator'
177-
- include: '#imply-operator'
178177
- include: '#operators'
179178
- include: '#function-call'
180179

@@ -946,10 +945,6 @@ repository:
946945
- name: keyword.operator.is.ts
947946
match: \bis\b
948947

949-
imply-operator:
950-
name: storage.type.function.arrow.ts
951-
match: =>
952-
953948
operators:
954949
patterns:
955950
- name: keyword.operator.assignment.compound.ts
@@ -973,6 +968,33 @@ repository:
973968
- name: keyword.operator.arithmetic.ts
974969
match: '%|\*|/|-|\+'
975970

971+
arrow-function:
972+
patterns:
973+
# TODO: type parameter of arrow
974+
- name: meta.arrow.ts
975+
match: (\basync)(?=\s*[<(])
976+
captures:
977+
'1': { name: storage.modifier.async.ts }
978+
# paramters of the arrow
979+
- name: meta.arrow.ts
980+
match: ([_$[:alpha:]][_$[:alnum:]]*)\s*(=>)
981+
captures:
982+
'1': { name: variable.parameter.ts }
983+
'2': { name: storage.type.function.arrow.ts }
984+
- name: meta.arrow.ts
985+
begin: (?x)(?<=return|throw|yield|await|async|[=(,:>])\s*(?=\(([^()]+|\([^()]*\))*\)\s*=>)
986+
end: =>
987+
endCaptures:
988+
'0': { name: storage.type.function.arrow.ts }
989+
patterns:
990+
- include: '#function-parameters'
991+
# TODO: return type of the arrow
992+
# arrow operator for anything that doesnt get captured by above regex
993+
- name: storage.type.function.arrow.ts
994+
match: =>
995+
# body
996+
- include: '#arrow-body'
997+
976998
paren-expression:
977999
begin: \(
9781000
beginCaptures:

TypeScript.tmLanguage

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,78 @@
180180
</dict>
181181
</array>
182182
</dict>
183+
<key>arrow-function</key>
184+
<dict>
185+
<key>patterns</key>
186+
<array>
187+
<dict>
188+
<key>captures</key>
189+
<dict>
190+
<key>1</key>
191+
<dict>
192+
<key>name</key>
193+
<string>storage.modifier.async.ts</string>
194+
</dict>
195+
</dict>
196+
<key>match</key>
197+
<string>(\basync)(?=\s*[&lt;(])</string>
198+
<key>name</key>
199+
<string>meta.arrow.ts</string>
200+
</dict>
201+
<dict>
202+
<key>captures</key>
203+
<dict>
204+
<key>1</key>
205+
<dict>
206+
<key>name</key>
207+
<string>variable.parameter.ts</string>
208+
</dict>
209+
<key>2</key>
210+
<dict>
211+
<key>name</key>
212+
<string>storage.type.function.arrow.ts</string>
213+
</dict>
214+
</dict>
215+
<key>match</key>
216+
<string>([_$[:alpha:]][_$[:alnum:]]*)\s*(=&gt;)</string>
217+
<key>name</key>
218+
<string>meta.arrow.ts</string>
219+
</dict>
220+
<dict>
221+
<key>begin</key>
222+
<string>(?x)(?&lt;=return|throw|yield|await|async|[=(,:&gt;])\s*(?=\(([^()]+|\([^()]*\))*\)\s*=&gt;)</string>
223+
<key>end</key>
224+
<string>=&gt;</string>
225+
<key>endCaptures</key>
226+
<dict>
227+
<key>0</key>
228+
<dict>
229+
<key>name</key>
230+
<string>storage.type.function.arrow.ts</string>
231+
</dict>
232+
</dict>
233+
<key>name</key>
234+
<string>meta.arrow.ts</string>
235+
<key>patterns</key>
236+
<array>
237+
<dict>
238+
<key>include</key>
239+
<string>#function-parameters</string>
240+
</dict>
241+
</array>
242+
</dict>
243+
<dict>
244+
<key>match</key>
245+
<string>=&gt;</string>
246+
<key>name</key>
247+
<string>storage.type.function.arrow.ts</string>
248+
</dict>
249+
<dict>
250+
<key>include</key>
251+
<string>#arrow-body</string>
252+
</dict>
253+
</array>
254+
</dict>
183255
<key>boolean-literal</key>
184256
<dict>
185257
<key>patterns</key>
@@ -1089,23 +1161,23 @@
10891161
</dict>
10901162
<dict>
10911163
<key>include</key>
1092-
<string>#paren-expression</string>
1164+
<string>#cast</string>
10931165
</dict>
10941166
<dict>
10951167
<key>include</key>
1096-
<string>#ternary-expression</string>
1168+
<string>#arrow-function</string>
10971169
</dict>
10981170
<dict>
10991171
<key>include</key>
1100-
<string>#cast</string>
1172+
<string>#paren-expression</string>
11011173
</dict>
11021174
<dict>
11031175
<key>include</key>
1104-
<string>#new-expr</string>
1176+
<string>#ternary-expression</string>
11051177
</dict>
11061178
<dict>
11071179
<key>include</key>
1108-
<string>#arrow-body</string>
1180+
<string>#new-expr</string>
11091181
</dict>
11101182
<dict>
11111183
<key>include</key>
@@ -1115,10 +1187,6 @@
11151187
<key>include</key>
11161188
<string>#expression-operator</string>
11171189
</dict>
1118-
<dict>
1119-
<key>include</key>
1120-
<string>#imply-operator</string>
1121-
</dict>
11221190
<dict>
11231191
<key>include</key>
11241192
<string>#operators</string>
@@ -1447,13 +1515,6 @@
14471515
</dict>
14481516
</array>
14491517
</dict>
1450-
<key>imply-operator</key>
1451-
<dict>
1452-
<key>match</key>
1453-
<string>=&gt;</string>
1454-
<key>name</key>
1455-
<string>storage.type.function.arrow.ts</string>
1456-
</dict>
14571518
<key>import-declaration</key>
14581519
<dict>
14591520
<key>begin</key>

TypeScriptReact.YAML-tmLanguage

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,12 @@ repository:
172172
- include: '#literal'
173173
- include: '#function-declaration'
174174
- include: '#class-or-interface-declaration'
175+
- include: '#arrow-function'
175176
- include: '#paren-expression'
176177
- include: '#ternary-expression'
177178
- include: '#new-expr'
178-
- include: '#arrow-body'
179179
- include: '#object-literal'
180180
- include: '#expression-operator'
181-
- include: '#imply-operator'
182181
- include: '#operators'
183182
- include: '#function-call'
184183

@@ -701,7 +700,7 @@ repository:
701700
type-annotation:
702701
name: meta.type.annotation.tsx
703702
begin: ":"
704-
end: (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[a-zA-Z_$])\s*(?=\{)
703+
end: (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)
705704
patterns:
706705
- include: '#expression-operator'
707706
- include: '#type'
@@ -936,10 +935,6 @@ repository:
936935
- name: keyword.operator.is.tsx
937936
match: \bis\b
938937

939-
imply-operator:
940-
name: storage.type.function.arrow.tsx
941-
match: =>
942-
943938
operators:
944939
patterns:
945940
- name: keyword.operator.assignment.compound.tsx
@@ -963,6 +958,33 @@ repository:
963958
- name: keyword.operator.arithmetic.tsx
964959
match: '%|\*|/|-|\+'
965960

961+
arrow-function:
962+
patterns:
963+
# TODO: type parameter of arrow
964+
- name: meta.arrow.ts
965+
match: (\basync)(?=\s*[<(])
966+
captures:
967+
'1': { name: storage.modifier.async.tsx }
968+
# paramters of the arrow
969+
- name: meta.arrow.tsx
970+
match: ([_$[:alpha:]][_$[:alnum:]]*)\s*(=>)
971+
captures:
972+
'1': { name: variable.parameter.tsx }
973+
'2': { name: storage.type.function.arrow.tsx }
974+
- name: meta.arrow.tsx
975+
begin: (?x)(?<=return|throw|yield|await|async|[=(,:>])\s*(?=\(([^()]+|\([^()]*\))*\)\s*=>)
976+
end: =>
977+
endCaptures:
978+
'0': { name: storage.type.function.arrow.tsx }
979+
patterns:
980+
- include: '#function-parameters'
981+
# TODO: return type of the arrow
982+
# arrow operator for anything that doesnt get captured by above regex
983+
- name: storage.type.function.arrow.tsx
984+
match: =>
985+
# body
986+
- include: '#arrow-body'
987+
966988
paren-expression:
967989
begin: \(
968990
beginCaptures:

0 commit comments

Comments
 (0)