react-native-codepad-lang-tsx 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CodepadLangTsx.podspec +28 -0
- package/README.md +80 -2
- package/android/CMakeLists.txt +15 -0
- package/android/build.gradle +61 -0
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/assets/codepad-languages/tsx +1 -0
- package/android/src/main/cpp/lang.c +10 -0
- package/android/src/main/java/me/sectiontn/codepad/lang/tsx/CodepadLangTsxPackage.kt +13 -0
- package/android/src/main/java/me/sectiontn/codepad/lang/tsx/TsxLanguage.kt +1046 -0
- package/grammar/LICENSE +21 -0
- package/grammar/common/scanner.h +347 -0
- package/grammar/tsx/src/parser.c +282955 -0
- package/grammar/tsx/src/scanner.c +13 -0
- package/grammar/tsx/src/tree_sitter/alloc.h +54 -0
- package/grammar/tsx/src/tree_sitter/array.h +290 -0
- package/grammar/tsx/src/tree_sitter/parser.h +266 -0
- package/ios/CPLangTsx.h +11 -0
- package/ios/CPLangTsx.swift +1039 -0
- package/package.json +40 -4
- package/queries/tsx/highlights.scm +762 -0
- package/queries/tsx/indents.scm +115 -0
- package/queries/tsx/injections.scm +263 -0
- package/queries/tsx/locals.scm +85 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,1046 @@
|
|
|
1
|
+
package me.sectiontn.codepad.lang.tsx
|
|
2
|
+
|
|
3
|
+
import me.sectiontn.codepad.syntax.LanguageProvider
|
|
4
|
+
|
|
5
|
+
class TsxLanguage : LanguageProvider {
|
|
6
|
+
override val id: String = "tsx"
|
|
7
|
+
override val languagePointer: Long get() = nativeLanguage()
|
|
8
|
+
override val highlights: String = HIGHLIGHTS
|
|
9
|
+
override val injections: String = INJECTIONS
|
|
10
|
+
|
|
11
|
+
private external fun nativeLanguage(): Long
|
|
12
|
+
|
|
13
|
+
companion object {
|
|
14
|
+
init {
|
|
15
|
+
System.loadLibrary("codepad_lang_tsx")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private val HIGHLIGHTS: String = """; inherited from typescript
|
|
19
|
+
; inherited from ecma
|
|
20
|
+
; Types
|
|
21
|
+
; Javascript
|
|
22
|
+
; Variables
|
|
23
|
+
;-----------
|
|
24
|
+
(identifier) @variable
|
|
25
|
+
|
|
26
|
+
; Properties
|
|
27
|
+
;-----------
|
|
28
|
+
(property_identifier) @variable.member
|
|
29
|
+
|
|
30
|
+
(shorthand_property_identifier) @variable.member
|
|
31
|
+
|
|
32
|
+
(private_property_identifier) @variable.member
|
|
33
|
+
|
|
34
|
+
(object_pattern
|
|
35
|
+
(shorthand_property_identifier_pattern) @variable)
|
|
36
|
+
|
|
37
|
+
(object_pattern
|
|
38
|
+
(object_assignment_pattern
|
|
39
|
+
(shorthand_property_identifier_pattern) @variable))
|
|
40
|
+
|
|
41
|
+
; Special identifiers
|
|
42
|
+
;--------------------
|
|
43
|
+
((identifier) @type
|
|
44
|
+
(#match? @type "^[A-Z]"))
|
|
45
|
+
|
|
46
|
+
((identifier) @constant
|
|
47
|
+
(#match? @constant "^_*[A-Z][A-Z0-9_]*${'$'}"))
|
|
48
|
+
|
|
49
|
+
((shorthand_property_identifier) @constant
|
|
50
|
+
(#match? @constant "^_*[A-Z][A-Z0-9_]*${'$'}"))
|
|
51
|
+
|
|
52
|
+
((identifier) @variable.builtin
|
|
53
|
+
(#any-of? @variable.builtin "arguments" "module" "console" "window" "document"))
|
|
54
|
+
|
|
55
|
+
((identifier) @type.builtin
|
|
56
|
+
(#any-of? @type.builtin
|
|
57
|
+
"Object" "Function" "Boolean" "Symbol" "Number" "Math" "Date" "String" "RegExp" "Map" "Set"
|
|
58
|
+
"WeakMap" "WeakSet" "Promise" "Array" "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array"
|
|
59
|
+
"Uint16Array" "Int32Array" "Uint32Array" "Float32Array" "Float64Array" "ArrayBuffer" "DataView"
|
|
60
|
+
"Error" "EvalError" "InternalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError"
|
|
61
|
+
"URIError"))
|
|
62
|
+
|
|
63
|
+
(statement_identifier) @label
|
|
64
|
+
|
|
65
|
+
; Function and method definitions
|
|
66
|
+
;--------------------------------
|
|
67
|
+
(function_expression
|
|
68
|
+
name: (identifier) @function)
|
|
69
|
+
|
|
70
|
+
(function_declaration
|
|
71
|
+
name: (identifier) @function)
|
|
72
|
+
|
|
73
|
+
(generator_function
|
|
74
|
+
name: (identifier) @function)
|
|
75
|
+
|
|
76
|
+
(generator_function_declaration
|
|
77
|
+
name: (identifier) @function)
|
|
78
|
+
|
|
79
|
+
(method_definition
|
|
80
|
+
name: [
|
|
81
|
+
(property_identifier)
|
|
82
|
+
(private_property_identifier)
|
|
83
|
+
] @function.method)
|
|
84
|
+
|
|
85
|
+
(method_definition
|
|
86
|
+
name: (property_identifier) @constructor
|
|
87
|
+
(#eq? @constructor "constructor"))
|
|
88
|
+
|
|
89
|
+
(pair
|
|
90
|
+
key: (property_identifier) @function.method
|
|
91
|
+
value: (function_expression))
|
|
92
|
+
|
|
93
|
+
(pair
|
|
94
|
+
key: (property_identifier) @function.method
|
|
95
|
+
value: (arrow_function))
|
|
96
|
+
|
|
97
|
+
(assignment_expression
|
|
98
|
+
left: (member_expression
|
|
99
|
+
property: (property_identifier) @function.method)
|
|
100
|
+
right: (arrow_function))
|
|
101
|
+
|
|
102
|
+
(assignment_expression
|
|
103
|
+
left: (member_expression
|
|
104
|
+
property: (property_identifier) @function.method)
|
|
105
|
+
right: (function_expression))
|
|
106
|
+
|
|
107
|
+
(variable_declarator
|
|
108
|
+
name: (identifier) @function
|
|
109
|
+
value: (arrow_function))
|
|
110
|
+
|
|
111
|
+
(variable_declarator
|
|
112
|
+
name: (identifier) @function
|
|
113
|
+
value: (function_expression))
|
|
114
|
+
|
|
115
|
+
(assignment_expression
|
|
116
|
+
left: (identifier) @function
|
|
117
|
+
right: (arrow_function))
|
|
118
|
+
|
|
119
|
+
(assignment_expression
|
|
120
|
+
left: (identifier) @function
|
|
121
|
+
right: (function_expression))
|
|
122
|
+
|
|
123
|
+
; Function and method calls
|
|
124
|
+
;--------------------------
|
|
125
|
+
(call_expression
|
|
126
|
+
function: (identifier) @function.call)
|
|
127
|
+
|
|
128
|
+
(call_expression
|
|
129
|
+
function: (member_expression
|
|
130
|
+
property: [
|
|
131
|
+
(property_identifier)
|
|
132
|
+
(private_property_identifier)
|
|
133
|
+
] @function.method.call))
|
|
134
|
+
|
|
135
|
+
(call_expression
|
|
136
|
+
function: (await_expression
|
|
137
|
+
(identifier) @function.call))
|
|
138
|
+
|
|
139
|
+
(call_expression
|
|
140
|
+
function: (await_expression
|
|
141
|
+
(member_expression
|
|
142
|
+
property: [
|
|
143
|
+
(property_identifier)
|
|
144
|
+
(private_property_identifier)
|
|
145
|
+
] @function.method.call)))
|
|
146
|
+
|
|
147
|
+
; Builtins
|
|
148
|
+
;---------
|
|
149
|
+
((identifier) @module.builtin
|
|
150
|
+
(#eq? @module.builtin "Intl"))
|
|
151
|
+
|
|
152
|
+
((identifier) @function.builtin
|
|
153
|
+
(#any-of? @function.builtin
|
|
154
|
+
"eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI"
|
|
155
|
+
"encodeURIComponent" "require"))
|
|
156
|
+
|
|
157
|
+
; Constructor
|
|
158
|
+
;------------
|
|
159
|
+
(new_expression
|
|
160
|
+
constructor: (identifier) @constructor)
|
|
161
|
+
|
|
162
|
+
; Decorators
|
|
163
|
+
;----------
|
|
164
|
+
(decorator
|
|
165
|
+
"@" @attribute
|
|
166
|
+
(identifier) @attribute)
|
|
167
|
+
|
|
168
|
+
(decorator
|
|
169
|
+
"@" @attribute
|
|
170
|
+
(call_expression
|
|
171
|
+
(identifier) @attribute))
|
|
172
|
+
|
|
173
|
+
(decorator
|
|
174
|
+
"@" @attribute
|
|
175
|
+
(member_expression
|
|
176
|
+
(property_identifier) @attribute))
|
|
177
|
+
|
|
178
|
+
(decorator
|
|
179
|
+
"@" @attribute
|
|
180
|
+
(call_expression
|
|
181
|
+
(member_expression
|
|
182
|
+
(property_identifier) @attribute)))
|
|
183
|
+
|
|
184
|
+
; Literals
|
|
185
|
+
;---------
|
|
186
|
+
[
|
|
187
|
+
(this)
|
|
188
|
+
(super)
|
|
189
|
+
] @variable.builtin
|
|
190
|
+
|
|
191
|
+
((identifier) @variable.builtin
|
|
192
|
+
(#eq? @variable.builtin "self"))
|
|
193
|
+
|
|
194
|
+
[
|
|
195
|
+
(true)
|
|
196
|
+
(false)
|
|
197
|
+
] @boolean
|
|
198
|
+
|
|
199
|
+
[
|
|
200
|
+
(null)
|
|
201
|
+
(undefined)
|
|
202
|
+
] @constant.builtin
|
|
203
|
+
|
|
204
|
+
[
|
|
205
|
+
(comment)
|
|
206
|
+
(html_comment)
|
|
207
|
+
] @comment @spell
|
|
208
|
+
|
|
209
|
+
((comment) @comment.documentation
|
|
210
|
+
(#match? @comment.documentation "^/[*][*][^*].*[*]/${'$'}"))
|
|
211
|
+
|
|
212
|
+
(hash_bang_line) @keyword.directive
|
|
213
|
+
|
|
214
|
+
((string_fragment) @keyword.directive
|
|
215
|
+
(#eq? @keyword.directive "use strict"))
|
|
216
|
+
|
|
217
|
+
(string) @string
|
|
218
|
+
|
|
219
|
+
(template_string) @string
|
|
220
|
+
|
|
221
|
+
(escape_sequence) @string.escape
|
|
222
|
+
|
|
223
|
+
(regex_pattern) @string.regexp
|
|
224
|
+
|
|
225
|
+
(regex_flags) @character.special
|
|
226
|
+
|
|
227
|
+
(regex
|
|
228
|
+
"/" @punctuation.bracket) ; Regex delimiters
|
|
229
|
+
|
|
230
|
+
(number) @number
|
|
231
|
+
|
|
232
|
+
((identifier) @number
|
|
233
|
+
(#any-of? @number "NaN" "Infinity"))
|
|
234
|
+
|
|
235
|
+
; Punctuation
|
|
236
|
+
;------------
|
|
237
|
+
[
|
|
238
|
+
";"
|
|
239
|
+
"."
|
|
240
|
+
","
|
|
241
|
+
":"
|
|
242
|
+
] @punctuation.delimiter
|
|
243
|
+
|
|
244
|
+
[
|
|
245
|
+
"--"
|
|
246
|
+
"-"
|
|
247
|
+
"-="
|
|
248
|
+
"&&"
|
|
249
|
+
"+"
|
|
250
|
+
"++"
|
|
251
|
+
"+="
|
|
252
|
+
"&="
|
|
253
|
+
"/="
|
|
254
|
+
"**="
|
|
255
|
+
"<<="
|
|
256
|
+
"<"
|
|
257
|
+
"<="
|
|
258
|
+
"<<"
|
|
259
|
+
"="
|
|
260
|
+
"=="
|
|
261
|
+
"==="
|
|
262
|
+
"!="
|
|
263
|
+
"!=="
|
|
264
|
+
"=>"
|
|
265
|
+
">"
|
|
266
|
+
">="
|
|
267
|
+
">>"
|
|
268
|
+
"||"
|
|
269
|
+
"%"
|
|
270
|
+
"%="
|
|
271
|
+
"*"
|
|
272
|
+
"**"
|
|
273
|
+
">>>"
|
|
274
|
+
"&"
|
|
275
|
+
"|"
|
|
276
|
+
"^"
|
|
277
|
+
"??"
|
|
278
|
+
"*="
|
|
279
|
+
">>="
|
|
280
|
+
">>>="
|
|
281
|
+
"^="
|
|
282
|
+
"|="
|
|
283
|
+
"&&="
|
|
284
|
+
"||="
|
|
285
|
+
"??="
|
|
286
|
+
"..."
|
|
287
|
+
] @operator
|
|
288
|
+
|
|
289
|
+
(binary_expression
|
|
290
|
+
"/" @operator)
|
|
291
|
+
|
|
292
|
+
(ternary_expression
|
|
293
|
+
[
|
|
294
|
+
"?"
|
|
295
|
+
":"
|
|
296
|
+
] @keyword.conditional.ternary)
|
|
297
|
+
|
|
298
|
+
(unary_expression
|
|
299
|
+
[
|
|
300
|
+
"!"
|
|
301
|
+
"~"
|
|
302
|
+
"-"
|
|
303
|
+
"+"
|
|
304
|
+
] @operator)
|
|
305
|
+
|
|
306
|
+
(unary_expression
|
|
307
|
+
[
|
|
308
|
+
"delete"
|
|
309
|
+
"void"
|
|
310
|
+
] @keyword.operator)
|
|
311
|
+
|
|
312
|
+
[
|
|
313
|
+
"("
|
|
314
|
+
")"
|
|
315
|
+
"["
|
|
316
|
+
"]"
|
|
317
|
+
"{"
|
|
318
|
+
"}"
|
|
319
|
+
] @punctuation.bracket
|
|
320
|
+
|
|
321
|
+
(template_substitution
|
|
322
|
+
[
|
|
323
|
+
"${'$'}{"
|
|
324
|
+
"}"
|
|
325
|
+
] @punctuation.special) @none
|
|
326
|
+
|
|
327
|
+
; Imports
|
|
328
|
+
;----------
|
|
329
|
+
(namespace_import
|
|
330
|
+
"*" @character.special
|
|
331
|
+
(identifier) @module)
|
|
332
|
+
|
|
333
|
+
(namespace_export
|
|
334
|
+
"*" @character.special
|
|
335
|
+
(identifier) @module)
|
|
336
|
+
|
|
337
|
+
(export_statement
|
|
338
|
+
"*" @character.special)
|
|
339
|
+
|
|
340
|
+
; Keywords
|
|
341
|
+
;----------
|
|
342
|
+
[
|
|
343
|
+
"if"
|
|
344
|
+
"else"
|
|
345
|
+
"switch"
|
|
346
|
+
"case"
|
|
347
|
+
] @keyword.conditional
|
|
348
|
+
|
|
349
|
+
[
|
|
350
|
+
"import"
|
|
351
|
+
"from"
|
|
352
|
+
"as"
|
|
353
|
+
"export"
|
|
354
|
+
] @keyword.import
|
|
355
|
+
|
|
356
|
+
[
|
|
357
|
+
"for"
|
|
358
|
+
"of"
|
|
359
|
+
"do"
|
|
360
|
+
"while"
|
|
361
|
+
"continue"
|
|
362
|
+
] @keyword.repeat
|
|
363
|
+
|
|
364
|
+
[
|
|
365
|
+
"break"
|
|
366
|
+
"const"
|
|
367
|
+
"debugger"
|
|
368
|
+
"extends"
|
|
369
|
+
"get"
|
|
370
|
+
"let"
|
|
371
|
+
"set"
|
|
372
|
+
"static"
|
|
373
|
+
"target"
|
|
374
|
+
"var"
|
|
375
|
+
"with"
|
|
376
|
+
] @keyword
|
|
377
|
+
|
|
378
|
+
"class" @keyword.type
|
|
379
|
+
|
|
380
|
+
[
|
|
381
|
+
"async"
|
|
382
|
+
"await"
|
|
383
|
+
] @keyword.coroutine
|
|
384
|
+
|
|
385
|
+
[
|
|
386
|
+
"return"
|
|
387
|
+
"yield"
|
|
388
|
+
] @keyword.return
|
|
389
|
+
|
|
390
|
+
"function" @keyword.function
|
|
391
|
+
|
|
392
|
+
[
|
|
393
|
+
"new"
|
|
394
|
+
"delete"
|
|
395
|
+
"in"
|
|
396
|
+
"instanceof"
|
|
397
|
+
"typeof"
|
|
398
|
+
] @keyword.operator
|
|
399
|
+
|
|
400
|
+
[
|
|
401
|
+
"throw"
|
|
402
|
+
"try"
|
|
403
|
+
"catch"
|
|
404
|
+
"finally"
|
|
405
|
+
] @keyword.exception
|
|
406
|
+
|
|
407
|
+
(export_statement
|
|
408
|
+
"default" @keyword)
|
|
409
|
+
|
|
410
|
+
(switch_default
|
|
411
|
+
"default" @keyword.conditional)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
"require" @keyword.import
|
|
415
|
+
|
|
416
|
+
(import_require_clause
|
|
417
|
+
source: (string) @string.special.url)
|
|
418
|
+
|
|
419
|
+
[
|
|
420
|
+
"declare"
|
|
421
|
+
"implements"
|
|
422
|
+
"type"
|
|
423
|
+
"override"
|
|
424
|
+
"module"
|
|
425
|
+
"asserts"
|
|
426
|
+
"infer"
|
|
427
|
+
"is"
|
|
428
|
+
"using"
|
|
429
|
+
] @keyword
|
|
430
|
+
|
|
431
|
+
[
|
|
432
|
+
"namespace"
|
|
433
|
+
"interface"
|
|
434
|
+
"enum"
|
|
435
|
+
] @keyword.type
|
|
436
|
+
|
|
437
|
+
[
|
|
438
|
+
"keyof"
|
|
439
|
+
"satisfies"
|
|
440
|
+
] @keyword.operator
|
|
441
|
+
|
|
442
|
+
(as_expression
|
|
443
|
+
"as" @keyword.operator)
|
|
444
|
+
|
|
445
|
+
(mapped_type_clause
|
|
446
|
+
"as" @keyword.operator)
|
|
447
|
+
|
|
448
|
+
[
|
|
449
|
+
"abstract"
|
|
450
|
+
"private"
|
|
451
|
+
"protected"
|
|
452
|
+
"public"
|
|
453
|
+
"readonly"
|
|
454
|
+
] @keyword.modifier
|
|
455
|
+
|
|
456
|
+
; types
|
|
457
|
+
(type_identifier) @type
|
|
458
|
+
|
|
459
|
+
(predefined_type) @type.builtin
|
|
460
|
+
|
|
461
|
+
(import_statement
|
|
462
|
+
"type"
|
|
463
|
+
(import_clause
|
|
464
|
+
(named_imports
|
|
465
|
+
(import_specifier
|
|
466
|
+
name: (identifier) @type))))
|
|
467
|
+
|
|
468
|
+
(template_literal_type) @string
|
|
469
|
+
|
|
470
|
+
(non_null_expression
|
|
471
|
+
"!" @operator)
|
|
472
|
+
|
|
473
|
+
; punctuation
|
|
474
|
+
(type_arguments
|
|
475
|
+
[
|
|
476
|
+
"<"
|
|
477
|
+
">"
|
|
478
|
+
] @punctuation.bracket)
|
|
479
|
+
|
|
480
|
+
(type_parameters
|
|
481
|
+
[
|
|
482
|
+
"<"
|
|
483
|
+
">"
|
|
484
|
+
] @punctuation.bracket)
|
|
485
|
+
|
|
486
|
+
(object_type
|
|
487
|
+
[
|
|
488
|
+
"{|"
|
|
489
|
+
"|}"
|
|
490
|
+
] @punctuation.bracket)
|
|
491
|
+
|
|
492
|
+
(union_type
|
|
493
|
+
"|" @punctuation.delimiter)
|
|
494
|
+
|
|
495
|
+
(intersection_type
|
|
496
|
+
"&" @punctuation.delimiter)
|
|
497
|
+
|
|
498
|
+
(type_annotation
|
|
499
|
+
":" @punctuation.delimiter)
|
|
500
|
+
|
|
501
|
+
(type_predicate_annotation
|
|
502
|
+
":" @punctuation.delimiter)
|
|
503
|
+
|
|
504
|
+
(index_signature
|
|
505
|
+
":" @punctuation.delimiter)
|
|
506
|
+
|
|
507
|
+
(omitting_type_annotation
|
|
508
|
+
"-?:" @punctuation.delimiter)
|
|
509
|
+
|
|
510
|
+
(adding_type_annotation
|
|
511
|
+
"+?:" @punctuation.delimiter)
|
|
512
|
+
|
|
513
|
+
(opting_type_annotation
|
|
514
|
+
"?:" @punctuation.delimiter)
|
|
515
|
+
|
|
516
|
+
"?." @punctuation.delimiter
|
|
517
|
+
|
|
518
|
+
(abstract_method_signature
|
|
519
|
+
"?" @punctuation.special)
|
|
520
|
+
|
|
521
|
+
(method_signature
|
|
522
|
+
"?" @punctuation.special)
|
|
523
|
+
|
|
524
|
+
(method_definition
|
|
525
|
+
"?" @punctuation.special)
|
|
526
|
+
|
|
527
|
+
(property_signature
|
|
528
|
+
"?" @punctuation.special)
|
|
529
|
+
|
|
530
|
+
(optional_parameter
|
|
531
|
+
"?" @punctuation.special)
|
|
532
|
+
|
|
533
|
+
(optional_type
|
|
534
|
+
"?" @punctuation.special)
|
|
535
|
+
|
|
536
|
+
(public_field_definition
|
|
537
|
+
[
|
|
538
|
+
"?"
|
|
539
|
+
"!"
|
|
540
|
+
] @punctuation.special)
|
|
541
|
+
|
|
542
|
+
(flow_maybe_type
|
|
543
|
+
"?" @punctuation.special)
|
|
544
|
+
|
|
545
|
+
(template_type
|
|
546
|
+
[
|
|
547
|
+
"${'$'}{"
|
|
548
|
+
"}"
|
|
549
|
+
] @punctuation.special)
|
|
550
|
+
|
|
551
|
+
(conditional_type
|
|
552
|
+
[
|
|
553
|
+
"?"
|
|
554
|
+
":"
|
|
555
|
+
] @keyword.conditional.ternary)
|
|
556
|
+
|
|
557
|
+
; Parameters
|
|
558
|
+
(required_parameter
|
|
559
|
+
pattern: (identifier) @variable.parameter)
|
|
560
|
+
|
|
561
|
+
(optional_parameter
|
|
562
|
+
pattern: (identifier) @variable.parameter)
|
|
563
|
+
|
|
564
|
+
(required_parameter
|
|
565
|
+
(rest_pattern
|
|
566
|
+
(identifier) @variable.parameter))
|
|
567
|
+
|
|
568
|
+
; ({ a }) => null
|
|
569
|
+
(required_parameter
|
|
570
|
+
(object_pattern
|
|
571
|
+
(shorthand_property_identifier_pattern) @variable.parameter))
|
|
572
|
+
|
|
573
|
+
; ({ a = b }) => null
|
|
574
|
+
(required_parameter
|
|
575
|
+
(object_pattern
|
|
576
|
+
(object_assignment_pattern
|
|
577
|
+
(shorthand_property_identifier_pattern) @variable.parameter)))
|
|
578
|
+
|
|
579
|
+
; ({ a: b }) => null
|
|
580
|
+
(required_parameter
|
|
581
|
+
(object_pattern
|
|
582
|
+
(pair_pattern
|
|
583
|
+
value: (identifier) @variable.parameter)))
|
|
584
|
+
|
|
585
|
+
; ([ a ]) => null
|
|
586
|
+
(required_parameter
|
|
587
|
+
(array_pattern
|
|
588
|
+
(identifier) @variable.parameter))
|
|
589
|
+
|
|
590
|
+
; a => null
|
|
591
|
+
(arrow_function
|
|
592
|
+
parameter: (identifier) @variable.parameter)
|
|
593
|
+
|
|
594
|
+
; global declaration
|
|
595
|
+
(ambient_declaration
|
|
596
|
+
"global" @module)
|
|
597
|
+
|
|
598
|
+
; function signatures
|
|
599
|
+
(ambient_declaration
|
|
600
|
+
(function_signature
|
|
601
|
+
name: (identifier) @function))
|
|
602
|
+
|
|
603
|
+
; method signatures
|
|
604
|
+
(method_signature
|
|
605
|
+
name: (_) @function.method)
|
|
606
|
+
|
|
607
|
+
(abstract_method_signature
|
|
608
|
+
name: (property_identifier) @function.method)
|
|
609
|
+
|
|
610
|
+
; property signatures
|
|
611
|
+
(property_signature
|
|
612
|
+
name: (property_identifier) @function.method
|
|
613
|
+
type: (type_annotation
|
|
614
|
+
[
|
|
615
|
+
(union_type
|
|
616
|
+
(parenthesized_type
|
|
617
|
+
(function_type)))
|
|
618
|
+
(function_type)
|
|
619
|
+
]))
|
|
620
|
+
|
|
621
|
+
; inherited from jsx
|
|
622
|
+
(jsx_element
|
|
623
|
+
open_tag: (jsx_opening_element
|
|
624
|
+
[
|
|
625
|
+
"<"
|
|
626
|
+
">"
|
|
627
|
+
] @tag.delimiter))
|
|
628
|
+
|
|
629
|
+
(jsx_element
|
|
630
|
+
close_tag: (jsx_closing_element
|
|
631
|
+
[
|
|
632
|
+
"</"
|
|
633
|
+
">"
|
|
634
|
+
] @tag.delimiter))
|
|
635
|
+
|
|
636
|
+
(jsx_self_closing_element
|
|
637
|
+
[
|
|
638
|
+
"<"
|
|
639
|
+
"/>"
|
|
640
|
+
] @tag.delimiter)
|
|
641
|
+
|
|
642
|
+
(jsx_attribute
|
|
643
|
+
(property_identifier) @tag.attribute)
|
|
644
|
+
|
|
645
|
+
(jsx_opening_element
|
|
646
|
+
name: (identifier) @tag.builtin)
|
|
647
|
+
|
|
648
|
+
(jsx_closing_element
|
|
649
|
+
name: (identifier) @tag.builtin)
|
|
650
|
+
|
|
651
|
+
(jsx_self_closing_element
|
|
652
|
+
name: (identifier) @tag.builtin)
|
|
653
|
+
|
|
654
|
+
(jsx_opening_element
|
|
655
|
+
((identifier) @tag
|
|
656
|
+
(#match? @tag "^[A-Z]")))
|
|
657
|
+
|
|
658
|
+
; Handle the dot operator effectively - <My.Component>
|
|
659
|
+
(jsx_opening_element
|
|
660
|
+
(member_expression
|
|
661
|
+
(identifier) @tag.builtin
|
|
662
|
+
(property_identifier) @tag))
|
|
663
|
+
|
|
664
|
+
(jsx_closing_element
|
|
665
|
+
((identifier) @tag
|
|
666
|
+
(#match? @tag "^[A-Z]")))
|
|
667
|
+
|
|
668
|
+
; Handle the dot operator effectively - </My.Component>
|
|
669
|
+
(jsx_closing_element
|
|
670
|
+
(member_expression
|
|
671
|
+
(identifier) @tag.builtin
|
|
672
|
+
(property_identifier) @tag))
|
|
673
|
+
|
|
674
|
+
(jsx_self_closing_element
|
|
675
|
+
((identifier) @tag
|
|
676
|
+
(#match? @tag "^[A-Z]")))
|
|
677
|
+
|
|
678
|
+
; Handle the dot operator effectively - <My.Component />
|
|
679
|
+
(jsx_self_closing_element
|
|
680
|
+
(member_expression
|
|
681
|
+
(identifier) @tag.builtin
|
|
682
|
+
(property_identifier) @tag))
|
|
683
|
+
|
|
684
|
+
(html_character_reference) @tag
|
|
685
|
+
|
|
686
|
+
(jsx_text) @none @spell
|
|
687
|
+
|
|
688
|
+
(html_character_reference) @character.special
|
|
689
|
+
|
|
690
|
+
((jsx_element
|
|
691
|
+
(jsx_opening_element
|
|
692
|
+
name: (identifier) @_tag)
|
|
693
|
+
(jsx_text) @markup.heading)
|
|
694
|
+
(#eq? @_tag "title"))
|
|
695
|
+
|
|
696
|
+
((jsx_element
|
|
697
|
+
(jsx_opening_element
|
|
698
|
+
name: (identifier) @_tag)
|
|
699
|
+
(jsx_text) @markup.heading.1)
|
|
700
|
+
(#eq? @_tag "h1"))
|
|
701
|
+
|
|
702
|
+
((jsx_element
|
|
703
|
+
(jsx_opening_element
|
|
704
|
+
name: (identifier) @_tag)
|
|
705
|
+
(jsx_text) @markup.heading.2)
|
|
706
|
+
(#eq? @_tag "h2"))
|
|
707
|
+
|
|
708
|
+
((jsx_element
|
|
709
|
+
(jsx_opening_element
|
|
710
|
+
name: (identifier) @_tag)
|
|
711
|
+
(jsx_text) @markup.heading.3)
|
|
712
|
+
(#eq? @_tag "h3"))
|
|
713
|
+
|
|
714
|
+
((jsx_element
|
|
715
|
+
(jsx_opening_element
|
|
716
|
+
name: (identifier) @_tag)
|
|
717
|
+
(jsx_text) @markup.heading.4)
|
|
718
|
+
(#eq? @_tag "h4"))
|
|
719
|
+
|
|
720
|
+
((jsx_element
|
|
721
|
+
(jsx_opening_element
|
|
722
|
+
name: (identifier) @_tag)
|
|
723
|
+
(jsx_text) @markup.heading.5)
|
|
724
|
+
(#eq? @_tag "h5"))
|
|
725
|
+
|
|
726
|
+
((jsx_element
|
|
727
|
+
(jsx_opening_element
|
|
728
|
+
name: (identifier) @_tag)
|
|
729
|
+
(jsx_text) @markup.heading.6)
|
|
730
|
+
(#eq? @_tag "h6"))
|
|
731
|
+
|
|
732
|
+
((jsx_element
|
|
733
|
+
(jsx_opening_element
|
|
734
|
+
name: (identifier) @_tag)
|
|
735
|
+
(jsx_text) @markup.strong)
|
|
736
|
+
(#any-of? @_tag "strong" "b"))
|
|
737
|
+
|
|
738
|
+
((jsx_element
|
|
739
|
+
(jsx_opening_element
|
|
740
|
+
name: (identifier) @_tag)
|
|
741
|
+
(jsx_text) @markup.italic)
|
|
742
|
+
(#any-of? @_tag "em" "i"))
|
|
743
|
+
|
|
744
|
+
((jsx_element
|
|
745
|
+
(jsx_opening_element
|
|
746
|
+
name: (identifier) @_tag)
|
|
747
|
+
(jsx_text) @markup.strikethrough)
|
|
748
|
+
(#any-of? @_tag "s" "del"))
|
|
749
|
+
|
|
750
|
+
((jsx_element
|
|
751
|
+
(jsx_opening_element
|
|
752
|
+
name: (identifier) @_tag)
|
|
753
|
+
(jsx_text) @markup.underline)
|
|
754
|
+
(#eq? @_tag "u"))
|
|
755
|
+
|
|
756
|
+
((jsx_element
|
|
757
|
+
(jsx_opening_element
|
|
758
|
+
name: (identifier) @_tag)
|
|
759
|
+
(jsx_text) @markup.raw)
|
|
760
|
+
(#any-of? @_tag "code" "kbd"))
|
|
761
|
+
|
|
762
|
+
((jsx_element
|
|
763
|
+
(jsx_opening_element
|
|
764
|
+
name: (identifier) @_tag)
|
|
765
|
+
(jsx_text) @markup.link.label)
|
|
766
|
+
(#eq? @_tag "a"))
|
|
767
|
+
|
|
768
|
+
((jsx_attribute
|
|
769
|
+
(property_identifier) @_attr
|
|
770
|
+
(string
|
|
771
|
+
(string_fragment) @string.special.url))
|
|
772
|
+
(#any-of? @_attr "href" "src"))
|
|
773
|
+
|
|
774
|
+
((jsx_element) @_jsx_element
|
|
775
|
+
(#set! @_jsx_element bo.commentstring "{/* %s */}"))
|
|
776
|
+
|
|
777
|
+
((jsx_attribute) @_jsx_attribute
|
|
778
|
+
(#set! @_jsx_attribute bo.commentstring "// %s"))
|
|
779
|
+
|
|
780
|
+
"""
|
|
781
|
+
private val INJECTIONS: String = """; inherited from typescript
|
|
782
|
+
; inherited from ecma
|
|
783
|
+
(((comment) @_jsdoc_comment
|
|
784
|
+
(#match? @_jsdoc_comment "^/[*][*][^*].*[*]/${'$'}")) @injection.content
|
|
785
|
+
(#set! injection.language "jsdoc"))
|
|
786
|
+
|
|
787
|
+
((comment) @injection.content
|
|
788
|
+
(#set! injection.language "comment"))
|
|
789
|
+
|
|
790
|
+
; html(`...`), html`...`, sql(`...`), etc.
|
|
791
|
+
(call_expression
|
|
792
|
+
function: (identifier) @injection.language
|
|
793
|
+
arguments: [
|
|
794
|
+
(arguments
|
|
795
|
+
(template_string) @injection.content)
|
|
796
|
+
(template_string) @injection.content
|
|
797
|
+
]
|
|
798
|
+
(#match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*${'$'}")
|
|
799
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
800
|
+
(#set! injection.include-children)
|
|
801
|
+
; Languages excluded from auto-injection due to special rules
|
|
802
|
+
; - svg uses the html parser
|
|
803
|
+
; - css uses the styled parser
|
|
804
|
+
(#not-any-of? @injection.language "svg" "css"))
|
|
805
|
+
|
|
806
|
+
; svg`...` or svg(`...`)
|
|
807
|
+
(call_expression
|
|
808
|
+
function: (identifier) @_name
|
|
809
|
+
(#eq? @_name "svg")
|
|
810
|
+
arguments: [
|
|
811
|
+
(arguments
|
|
812
|
+
(template_string) @injection.content)
|
|
813
|
+
(template_string) @injection.content
|
|
814
|
+
]
|
|
815
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
816
|
+
(#set! injection.include-children)
|
|
817
|
+
(#set! injection.language "html"))
|
|
818
|
+
|
|
819
|
+
; Vercel PostgreSQL
|
|
820
|
+
; foo.sql`...` or foo.sql(`...`)
|
|
821
|
+
(call_expression
|
|
822
|
+
function: (member_expression
|
|
823
|
+
property: (property_identifier) @injection.language)
|
|
824
|
+
arguments: [
|
|
825
|
+
(arguments
|
|
826
|
+
(template_string) @injection.content)
|
|
827
|
+
(template_string) @injection.content
|
|
828
|
+
]
|
|
829
|
+
(#eq? @injection.language "sql")
|
|
830
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
831
|
+
(#set! injection.include-children))
|
|
832
|
+
|
|
833
|
+
; Sanity CMS GROQ query
|
|
834
|
+
; defineQuery(`...`)
|
|
835
|
+
(call_expression
|
|
836
|
+
function: (identifier) @_name
|
|
837
|
+
(#eq? @_name "defineQuery")
|
|
838
|
+
arguments: (arguments
|
|
839
|
+
(template_string) @injection.content)
|
|
840
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
841
|
+
(#set! injection.include-children)
|
|
842
|
+
(#set! injection.language "groq"))
|
|
843
|
+
|
|
844
|
+
; gql`...` or gql(`...`)
|
|
845
|
+
(call_expression
|
|
846
|
+
function: (identifier) @_name
|
|
847
|
+
(#eq? @_name "gql")
|
|
848
|
+
arguments: [
|
|
849
|
+
(arguments
|
|
850
|
+
(template_string) @injection.content)
|
|
851
|
+
(template_string) @injection.content
|
|
852
|
+
]
|
|
853
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
854
|
+
(#set! injection.include-children)
|
|
855
|
+
(#set! injection.language "graphql"))
|
|
856
|
+
|
|
857
|
+
(call_expression
|
|
858
|
+
function: (identifier) @_name
|
|
859
|
+
(#eq? @_name "hbs")
|
|
860
|
+
arguments: (template_string) @injection.content
|
|
861
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
862
|
+
(#set! injection.include-children)
|
|
863
|
+
(#set! injection.language "glimmer"))
|
|
864
|
+
|
|
865
|
+
; css`<css>`, keyframes`<css>`
|
|
866
|
+
(call_expression
|
|
867
|
+
function: (identifier) @_name
|
|
868
|
+
(#any-of? @_name "css" "keyframes")
|
|
869
|
+
arguments: (template_string) @injection.content
|
|
870
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
871
|
+
(#set! injection.include-children)
|
|
872
|
+
(#set! injection.language "styled"))
|
|
873
|
+
|
|
874
|
+
; styled.div`<css>`
|
|
875
|
+
(call_expression
|
|
876
|
+
function: (member_expression
|
|
877
|
+
object: (identifier) @_name
|
|
878
|
+
(#eq? @_name "styled"))
|
|
879
|
+
arguments: ((template_string) @injection.content
|
|
880
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
881
|
+
(#set! injection.include-children)
|
|
882
|
+
(#set! injection.language "styled")))
|
|
883
|
+
|
|
884
|
+
; styled(Component)`<css>`
|
|
885
|
+
(call_expression
|
|
886
|
+
function: (call_expression
|
|
887
|
+
function: (identifier) @_name
|
|
888
|
+
(#eq? @_name "styled"))
|
|
889
|
+
arguments: ((template_string) @injection.content
|
|
890
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
891
|
+
(#set! injection.include-children)
|
|
892
|
+
(#set! injection.language "styled")))
|
|
893
|
+
|
|
894
|
+
; styled.div.attrs({ prop: "foo" })`<css>`
|
|
895
|
+
(call_expression
|
|
896
|
+
function: (call_expression
|
|
897
|
+
function: (member_expression
|
|
898
|
+
object: (member_expression
|
|
899
|
+
object: (identifier) @_name
|
|
900
|
+
(#eq? @_name "styled"))))
|
|
901
|
+
arguments: ((template_string) @injection.content
|
|
902
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
903
|
+
(#set! injection.include-children)
|
|
904
|
+
(#set! injection.language "styled")))
|
|
905
|
+
|
|
906
|
+
; styled(Component).attrs({ prop: "foo" })`<css>`
|
|
907
|
+
(call_expression
|
|
908
|
+
function: (call_expression
|
|
909
|
+
function: (member_expression
|
|
910
|
+
object: (call_expression
|
|
911
|
+
function: (identifier) @_name
|
|
912
|
+
(#eq? @_name "styled"))))
|
|
913
|
+
arguments: ((template_string) @injection.content
|
|
914
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
915
|
+
(#set! injection.include-children)
|
|
916
|
+
(#set! injection.language "styled")))
|
|
917
|
+
|
|
918
|
+
((regex_pattern) @injection.content
|
|
919
|
+
(#set! injection.language "regex"))
|
|
920
|
+
|
|
921
|
+
; ((comment) @_gql_comment
|
|
922
|
+
; (#eq? @_gql_comment "/* GraphQL */")
|
|
923
|
+
; (template_string) @injection.content
|
|
924
|
+
; (#set! injection.language "graphql"))
|
|
925
|
+
((template_string) @injection.content
|
|
926
|
+
(#match? @injection.content "^`#graphql")
|
|
927
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
928
|
+
(#set! injection.include-children)
|
|
929
|
+
(#set! injection.language "graphql"))
|
|
930
|
+
|
|
931
|
+
; el.innerHTML = `<html>`
|
|
932
|
+
(assignment_expression
|
|
933
|
+
left: (member_expression
|
|
934
|
+
property: (property_identifier) @_prop
|
|
935
|
+
(#any-of? @_prop "outerHTML" "innerHTML"))
|
|
936
|
+
right: (template_string) @injection.content
|
|
937
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
938
|
+
(#set! injection.include-children)
|
|
939
|
+
(#set! injection.language "html"))
|
|
940
|
+
|
|
941
|
+
; el.innerHTML = '<html>'
|
|
942
|
+
(assignment_expression
|
|
943
|
+
left: (member_expression
|
|
944
|
+
property: (property_identifier) @_prop
|
|
945
|
+
(#any-of? @_prop "outerHTML" "innerHTML"))
|
|
946
|
+
right: (string
|
|
947
|
+
(string_fragment) @injection.content)
|
|
948
|
+
(#set! injection.language "html"))
|
|
949
|
+
|
|
950
|
+
;---- Angular injections -----
|
|
951
|
+
; @Component({
|
|
952
|
+
; template: `<html>`
|
|
953
|
+
; })
|
|
954
|
+
(decorator
|
|
955
|
+
(call_expression
|
|
956
|
+
function: ((identifier) @_name
|
|
957
|
+
(#eq? @_name "Component"))
|
|
958
|
+
arguments: (arguments
|
|
959
|
+
(object
|
|
960
|
+
(pair
|
|
961
|
+
key: ((property_identifier) @_prop
|
|
962
|
+
(#eq? @_prop "template"))
|
|
963
|
+
value: ((template_string) @injection.content
|
|
964
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
965
|
+
(#set! injection.include-children)
|
|
966
|
+
(#set! injection.language "angular")))))))
|
|
967
|
+
|
|
968
|
+
; @Component({
|
|
969
|
+
; styles: [`<css>`]
|
|
970
|
+
; })
|
|
971
|
+
(decorator
|
|
972
|
+
(call_expression
|
|
973
|
+
function: ((identifier) @_name
|
|
974
|
+
(#eq? @_name "Component"))
|
|
975
|
+
arguments: (arguments
|
|
976
|
+
(object
|
|
977
|
+
(pair
|
|
978
|
+
key: ((property_identifier) @_prop
|
|
979
|
+
(#eq? @_prop "styles"))
|
|
980
|
+
value: (array
|
|
981
|
+
((template_string) @injection.content
|
|
982
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
983
|
+
(#set! injection.include-children)
|
|
984
|
+
(#set! injection.language "css"))))))))
|
|
985
|
+
|
|
986
|
+
; @Component({
|
|
987
|
+
; styles: `<css>`
|
|
988
|
+
; })
|
|
989
|
+
(decorator
|
|
990
|
+
(call_expression
|
|
991
|
+
function: ((identifier) @_name
|
|
992
|
+
(#eq? @_name "Component"))
|
|
993
|
+
arguments: (arguments
|
|
994
|
+
(object
|
|
995
|
+
(pair
|
|
996
|
+
key: ((property_identifier) @_prop
|
|
997
|
+
(#eq? @_prop "styles"))
|
|
998
|
+
value: ((template_string) @injection.content
|
|
999
|
+
(#set! injection.include-children)
|
|
1000
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
1001
|
+
(#set! injection.language "css")))))))
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
; styled.div<{}>`<css>`
|
|
1005
|
+
(call_expression
|
|
1006
|
+
function: (non_null_expression
|
|
1007
|
+
(instantiation_expression
|
|
1008
|
+
(member_expression
|
|
1009
|
+
object: (identifier) @_name
|
|
1010
|
+
(#eq? @_name "styled")
|
|
1011
|
+
property: (property_identifier))
|
|
1012
|
+
type_arguments: (type_arguments)))
|
|
1013
|
+
arguments: ((template_string) @injection.content
|
|
1014
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
1015
|
+
(#set! injection.include-children)
|
|
1016
|
+
(#set! injection.language "styled")))
|
|
1017
|
+
|
|
1018
|
+
; styled.div<T>`<css>`
|
|
1019
|
+
(binary_expression
|
|
1020
|
+
left: (binary_expression
|
|
1021
|
+
left: (member_expression
|
|
1022
|
+
object: (identifier) @_name
|
|
1023
|
+
(#eq? @_name "styled")
|
|
1024
|
+
property: (property_identifier))
|
|
1025
|
+
right: (identifier))
|
|
1026
|
+
right: (template_string) @injection.content
|
|
1027
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
1028
|
+
(#set! injection.include-children)
|
|
1029
|
+
(#set! injection.language "styled"))
|
|
1030
|
+
|
|
1031
|
+
; inherited from jsx
|
|
1032
|
+
; Styled Jsx <style jsx>
|
|
1033
|
+
(jsx_element
|
|
1034
|
+
(jsx_opening_element
|
|
1035
|
+
(identifier) @_name
|
|
1036
|
+
(#eq? @_name "style")
|
|
1037
|
+
(jsx_attribute) @_attr
|
|
1038
|
+
(#eq? @_attr "jsx"))
|
|
1039
|
+
(jsx_expression
|
|
1040
|
+
((template_string) @injection.content
|
|
1041
|
+
(#set! injection.language "css"))
|
|
1042
|
+
(#offset! @injection.content 0 1 0 -1)))
|
|
1043
|
+
|
|
1044
|
+
"""
|
|
1045
|
+
}
|
|
1046
|
+
}
|