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