react-native-codepad-lang-javascript 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/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "react-native-codepad-lang-javascript",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "tree-sitter Javascript grammar and highlight queries for react-native-codepad",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "files": [
8
+ "src",
9
+ "android",
10
+ "ios",
11
+ "grammar",
12
+ "queries",
13
+ "*.podspec",
14
+ "!android/build",
15
+ "!android/.cxx"
16
+ ],
17
+ "keywords": [
18
+ "react-native",
19
+ "codepad",
20
+ "tree-sitter",
21
+ "javascript"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/SectionTN/react-native-codepad.git",
26
+ "directory": "languages/javascript"
27
+ },
28
+ "author": "Rayen Sbai <rayensbai2@gmail.com> (https://github.com/SectionTN)",
29
+ "license": "MIT",
30
+ "homepage": "https://github.com/SectionTN/react-native-codepad#readme",
31
+ "peerDependencies": {
32
+ "react-native-codepad": "0.1.0"
33
+ },
34
+ "publishConfig": {
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "codepad": {
38
+ "generated": true,
39
+ "grammar": "tree-sitter/tree-sitter-javascript@58404d8cf191d69f2674a8fd507bd5776f46cb11",
40
+ "queries": "nvim-treesitter/nvim-treesitter@e289100ff98969e118c702199d88b764ce9e7fdf"
41
+ }
42
+ }
@@ -0,0 +1,608 @@
1
+ ; inherited from ecma
2
+ ; Types
3
+ ; Javascript
4
+ ; Variables
5
+ ;-----------
6
+ (identifier) @variable
7
+
8
+ ; Properties
9
+ ;-----------
10
+ (property_identifier) @variable.member
11
+
12
+ (shorthand_property_identifier) @variable.member
13
+
14
+ (private_property_identifier) @variable.member
15
+
16
+ (object_pattern
17
+ (shorthand_property_identifier_pattern) @variable)
18
+
19
+ (object_pattern
20
+ (object_assignment_pattern
21
+ (shorthand_property_identifier_pattern) @variable))
22
+
23
+ ; Special identifiers
24
+ ;--------------------
25
+ ((identifier) @type
26
+ (#match? @type "^[A-Z]"))
27
+
28
+ ((identifier) @constant
29
+ (#match? @constant "^_*[A-Z][A-Z0-9_]*$"))
30
+
31
+ ((shorthand_property_identifier) @constant
32
+ (#match? @constant "^_*[A-Z][A-Z0-9_]*$"))
33
+
34
+ ((identifier) @variable.builtin
35
+ (#any-of? @variable.builtin "arguments" "module" "console" "window" "document"))
36
+
37
+ ((identifier) @type.builtin
38
+ (#any-of? @type.builtin
39
+ "Object" "Function" "Boolean" "Symbol" "Number" "Math" "Date" "String" "RegExp" "Map" "Set"
40
+ "WeakMap" "WeakSet" "Promise" "Array" "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array"
41
+ "Uint16Array" "Int32Array" "Uint32Array" "Float32Array" "Float64Array" "ArrayBuffer" "DataView"
42
+ "Error" "EvalError" "InternalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError"
43
+ "URIError"))
44
+
45
+ (statement_identifier) @label
46
+
47
+ ; Function and method definitions
48
+ ;--------------------------------
49
+ (function_expression
50
+ name: (identifier) @function)
51
+
52
+ (function_declaration
53
+ name: (identifier) @function)
54
+
55
+ (generator_function
56
+ name: (identifier) @function)
57
+
58
+ (generator_function_declaration
59
+ name: (identifier) @function)
60
+
61
+ (method_definition
62
+ name: [
63
+ (property_identifier)
64
+ (private_property_identifier)
65
+ ] @function.method)
66
+
67
+ (method_definition
68
+ name: (property_identifier) @constructor
69
+ (#eq? @constructor "constructor"))
70
+
71
+ (pair
72
+ key: (property_identifier) @function.method
73
+ value: (function_expression))
74
+
75
+ (pair
76
+ key: (property_identifier) @function.method
77
+ value: (arrow_function))
78
+
79
+ (assignment_expression
80
+ left: (member_expression
81
+ property: (property_identifier) @function.method)
82
+ right: (arrow_function))
83
+
84
+ (assignment_expression
85
+ left: (member_expression
86
+ property: (property_identifier) @function.method)
87
+ right: (function_expression))
88
+
89
+ (variable_declarator
90
+ name: (identifier) @function
91
+ value: (arrow_function))
92
+
93
+ (variable_declarator
94
+ name: (identifier) @function
95
+ value: (function_expression))
96
+
97
+ (assignment_expression
98
+ left: (identifier) @function
99
+ right: (arrow_function))
100
+
101
+ (assignment_expression
102
+ left: (identifier) @function
103
+ right: (function_expression))
104
+
105
+ ; Function and method calls
106
+ ;--------------------------
107
+ (call_expression
108
+ function: (identifier) @function.call)
109
+
110
+ (call_expression
111
+ function: (member_expression
112
+ property: [
113
+ (property_identifier)
114
+ (private_property_identifier)
115
+ ] @function.method.call))
116
+
117
+ (call_expression
118
+ function: (await_expression
119
+ (identifier) @function.call))
120
+
121
+ (call_expression
122
+ function: (await_expression
123
+ (member_expression
124
+ property: [
125
+ (property_identifier)
126
+ (private_property_identifier)
127
+ ] @function.method.call)))
128
+
129
+ ; Builtins
130
+ ;---------
131
+ ((identifier) @module.builtin
132
+ (#eq? @module.builtin "Intl"))
133
+
134
+ ((identifier) @function.builtin
135
+ (#any-of? @function.builtin
136
+ "eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI"
137
+ "encodeURIComponent" "require"))
138
+
139
+ ; Constructor
140
+ ;------------
141
+ (new_expression
142
+ constructor: (identifier) @constructor)
143
+
144
+ ; Decorators
145
+ ;----------
146
+ (decorator
147
+ "@" @attribute
148
+ (identifier) @attribute)
149
+
150
+ (decorator
151
+ "@" @attribute
152
+ (call_expression
153
+ (identifier) @attribute))
154
+
155
+ (decorator
156
+ "@" @attribute
157
+ (member_expression
158
+ (property_identifier) @attribute))
159
+
160
+ (decorator
161
+ "@" @attribute
162
+ (call_expression
163
+ (member_expression
164
+ (property_identifier) @attribute)))
165
+
166
+ ; Literals
167
+ ;---------
168
+ [
169
+ (this)
170
+ (super)
171
+ ] @variable.builtin
172
+
173
+ ((identifier) @variable.builtin
174
+ (#eq? @variable.builtin "self"))
175
+
176
+ [
177
+ (true)
178
+ (false)
179
+ ] @boolean
180
+
181
+ [
182
+ (null)
183
+ (undefined)
184
+ ] @constant.builtin
185
+
186
+ [
187
+ (comment)
188
+ (html_comment)
189
+ ] @comment @spell
190
+
191
+ ((comment) @comment.documentation
192
+ (#match? @comment.documentation "^/[*][*][^*].*[*]/$"))
193
+
194
+ (hash_bang_line) @keyword.directive
195
+
196
+ ((string_fragment) @keyword.directive
197
+ (#eq? @keyword.directive "use strict"))
198
+
199
+ (string) @string
200
+
201
+ (template_string) @string
202
+
203
+ (escape_sequence) @string.escape
204
+
205
+ (regex_pattern) @string.regexp
206
+
207
+ (regex_flags) @character.special
208
+
209
+ (regex
210
+ "/" @punctuation.bracket) ; Regex delimiters
211
+
212
+ (number) @number
213
+
214
+ ((identifier) @number
215
+ (#any-of? @number "NaN" "Infinity"))
216
+
217
+ ; Punctuation
218
+ ;------------
219
+ [
220
+ ";"
221
+ "."
222
+ ","
223
+ ":"
224
+ ] @punctuation.delimiter
225
+
226
+ [
227
+ "--"
228
+ "-"
229
+ "-="
230
+ "&&"
231
+ "+"
232
+ "++"
233
+ "+="
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
+ ] @operator
270
+
271
+ (binary_expression
272
+ "/" @operator)
273
+
274
+ (ternary_expression
275
+ [
276
+ "?"
277
+ ":"
278
+ ] @keyword.conditional.ternary)
279
+
280
+ (unary_expression
281
+ [
282
+ "!"
283
+ "~"
284
+ "-"
285
+ "+"
286
+ ] @operator)
287
+
288
+ (unary_expression
289
+ [
290
+ "delete"
291
+ "void"
292
+ ] @keyword.operator)
293
+
294
+ [
295
+ "("
296
+ ")"
297
+ "["
298
+ "]"
299
+ "{"
300
+ "}"
301
+ ] @punctuation.bracket
302
+
303
+ (template_substitution
304
+ [
305
+ "${"
306
+ "}"
307
+ ] @punctuation.special) @none
308
+
309
+ ; Imports
310
+ ;----------
311
+ (namespace_import
312
+ "*" @character.special
313
+ (identifier) @module)
314
+
315
+ (namespace_export
316
+ "*" @character.special
317
+ (identifier) @module)
318
+
319
+ (export_statement
320
+ "*" @character.special)
321
+
322
+ ; Keywords
323
+ ;----------
324
+ [
325
+ "if"
326
+ "else"
327
+ "switch"
328
+ "case"
329
+ ] @keyword.conditional
330
+
331
+ [
332
+ "import"
333
+ "from"
334
+ "as"
335
+ "export"
336
+ ] @keyword.import
337
+
338
+ [
339
+ "for"
340
+ "of"
341
+ "do"
342
+ "while"
343
+ "continue"
344
+ ] @keyword.repeat
345
+
346
+ [
347
+ "break"
348
+ "const"
349
+ "debugger"
350
+ "extends"
351
+ "get"
352
+ "let"
353
+ "set"
354
+ "static"
355
+ "target"
356
+ "var"
357
+ "with"
358
+ ] @keyword
359
+
360
+ "class" @keyword.type
361
+
362
+ [
363
+ "async"
364
+ "await"
365
+ ] @keyword.coroutine
366
+
367
+ [
368
+ "return"
369
+ "yield"
370
+ ] @keyword.return
371
+
372
+ "function" @keyword.function
373
+
374
+ [
375
+ "new"
376
+ "delete"
377
+ "in"
378
+ "instanceof"
379
+ "typeof"
380
+ ] @keyword.operator
381
+
382
+ [
383
+ "throw"
384
+ "try"
385
+ "catch"
386
+ "finally"
387
+ ] @keyword.exception
388
+
389
+ (export_statement
390
+ "default" @keyword)
391
+
392
+ (switch_default
393
+ "default" @keyword.conditional)
394
+
395
+ ; inherited from jsx
396
+ (jsx_element
397
+ open_tag: (jsx_opening_element
398
+ [
399
+ "<"
400
+ ">"
401
+ ] @tag.delimiter))
402
+
403
+ (jsx_element
404
+ close_tag: (jsx_closing_element
405
+ [
406
+ "</"
407
+ ">"
408
+ ] @tag.delimiter))
409
+
410
+ (jsx_self_closing_element
411
+ [
412
+ "<"
413
+ "/>"
414
+ ] @tag.delimiter)
415
+
416
+ (jsx_attribute
417
+ (property_identifier) @tag.attribute)
418
+
419
+ (jsx_opening_element
420
+ name: (identifier) @tag.builtin)
421
+
422
+ (jsx_closing_element
423
+ name: (identifier) @tag.builtin)
424
+
425
+ (jsx_self_closing_element
426
+ name: (identifier) @tag.builtin)
427
+
428
+ (jsx_opening_element
429
+ ((identifier) @tag
430
+ (#match? @tag "^[A-Z]")))
431
+
432
+ ; Handle the dot operator effectively - <My.Component>
433
+ (jsx_opening_element
434
+ (member_expression
435
+ (identifier) @tag.builtin
436
+ (property_identifier) @tag))
437
+
438
+ (jsx_closing_element
439
+ ((identifier) @tag
440
+ (#match? @tag "^[A-Z]")))
441
+
442
+ ; Handle the dot operator effectively - </My.Component>
443
+ (jsx_closing_element
444
+ (member_expression
445
+ (identifier) @tag.builtin
446
+ (property_identifier) @tag))
447
+
448
+ (jsx_self_closing_element
449
+ ((identifier) @tag
450
+ (#match? @tag "^[A-Z]")))
451
+
452
+ ; Handle the dot operator effectively - <My.Component />
453
+ (jsx_self_closing_element
454
+ (member_expression
455
+ (identifier) @tag.builtin
456
+ (property_identifier) @tag))
457
+
458
+ (html_character_reference) @tag
459
+
460
+ (jsx_text) @none @spell
461
+
462
+ (html_character_reference) @character.special
463
+
464
+ ((jsx_element
465
+ (jsx_opening_element
466
+ name: (identifier) @_tag)
467
+ (jsx_text) @markup.heading)
468
+ (#eq? @_tag "title"))
469
+
470
+ ((jsx_element
471
+ (jsx_opening_element
472
+ name: (identifier) @_tag)
473
+ (jsx_text) @markup.heading.1)
474
+ (#eq? @_tag "h1"))
475
+
476
+ ((jsx_element
477
+ (jsx_opening_element
478
+ name: (identifier) @_tag)
479
+ (jsx_text) @markup.heading.2)
480
+ (#eq? @_tag "h2"))
481
+
482
+ ((jsx_element
483
+ (jsx_opening_element
484
+ name: (identifier) @_tag)
485
+ (jsx_text) @markup.heading.3)
486
+ (#eq? @_tag "h3"))
487
+
488
+ ((jsx_element
489
+ (jsx_opening_element
490
+ name: (identifier) @_tag)
491
+ (jsx_text) @markup.heading.4)
492
+ (#eq? @_tag "h4"))
493
+
494
+ ((jsx_element
495
+ (jsx_opening_element
496
+ name: (identifier) @_tag)
497
+ (jsx_text) @markup.heading.5)
498
+ (#eq? @_tag "h5"))
499
+
500
+ ((jsx_element
501
+ (jsx_opening_element
502
+ name: (identifier) @_tag)
503
+ (jsx_text) @markup.heading.6)
504
+ (#eq? @_tag "h6"))
505
+
506
+ ((jsx_element
507
+ (jsx_opening_element
508
+ name: (identifier) @_tag)
509
+ (jsx_text) @markup.strong)
510
+ (#any-of? @_tag "strong" "b"))
511
+
512
+ ((jsx_element
513
+ (jsx_opening_element
514
+ name: (identifier) @_tag)
515
+ (jsx_text) @markup.italic)
516
+ (#any-of? @_tag "em" "i"))
517
+
518
+ ((jsx_element
519
+ (jsx_opening_element
520
+ name: (identifier) @_tag)
521
+ (jsx_text) @markup.strikethrough)
522
+ (#any-of? @_tag "s" "del"))
523
+
524
+ ((jsx_element
525
+ (jsx_opening_element
526
+ name: (identifier) @_tag)
527
+ (jsx_text) @markup.underline)
528
+ (#eq? @_tag "u"))
529
+
530
+ ((jsx_element
531
+ (jsx_opening_element
532
+ name: (identifier) @_tag)
533
+ (jsx_text) @markup.raw)
534
+ (#any-of? @_tag "code" "kbd"))
535
+
536
+ ((jsx_element
537
+ (jsx_opening_element
538
+ name: (identifier) @_tag)
539
+ (jsx_text) @markup.link.label)
540
+ (#eq? @_tag "a"))
541
+
542
+ ((jsx_attribute
543
+ (property_identifier) @_attr
544
+ (string
545
+ (string_fragment) @string.special.url))
546
+ (#any-of? @_attr "href" "src"))
547
+
548
+ ((jsx_element) @_jsx_element
549
+ (#set! @_jsx_element bo.commentstring "{/* %s */}"))
550
+
551
+ ((jsx_attribute) @_jsx_attribute
552
+ (#set! @_jsx_attribute bo.commentstring "// %s"))
553
+
554
+
555
+ ; Parameters
556
+ (formal_parameters
557
+ (identifier) @variable.parameter)
558
+
559
+ (formal_parameters
560
+ (rest_pattern
561
+ (identifier) @variable.parameter))
562
+
563
+ ; ({ a }) => null
564
+ (formal_parameters
565
+ (object_pattern
566
+ (shorthand_property_identifier_pattern) @variable.parameter))
567
+
568
+ ; ({ a = b }) => null
569
+ (formal_parameters
570
+ (object_pattern
571
+ (object_assignment_pattern
572
+ (shorthand_property_identifier_pattern) @variable.parameter)))
573
+
574
+ ; ({ a: b }) => null
575
+ (formal_parameters
576
+ (object_pattern
577
+ (pair_pattern
578
+ value: (identifier) @variable.parameter)))
579
+
580
+ ; ([ a ]) => null
581
+ (formal_parameters
582
+ (array_pattern
583
+ (identifier) @variable.parameter))
584
+
585
+ ; ({ a } = { a }) => null
586
+ (formal_parameters
587
+ (assignment_pattern
588
+ (object_pattern
589
+ (shorthand_property_identifier_pattern) @variable.parameter)))
590
+
591
+ ; ({ a = b } = { a }) => null
592
+ (formal_parameters
593
+ (assignment_pattern
594
+ (object_pattern
595
+ (object_assignment_pattern
596
+ (shorthand_property_identifier_pattern) @variable.parameter))))
597
+
598
+ ; a => null
599
+ (arrow_function
600
+ parameter: (identifier) @variable.parameter)
601
+
602
+ ; optional parameters
603
+ (formal_parameters
604
+ (assignment_pattern
605
+ left: (identifier) @variable.parameter))
606
+
607
+ ; punctuation
608
+ (optional_chain) @punctuation.delimiter