@willbooster/tree-sitter-javascript 5.0.0 → 5.0.2
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/grammar.js +161 -118
- package/package.json +1 -2
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/// <reference types="tree-sitter-cli/dsl" />
|
|
9
8
|
// @ts-check
|
|
10
9
|
|
|
10
|
+
// The CLI injects the DSL before loading this CommonJS grammar.
|
|
11
|
+
const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token, reserved } =
|
|
12
|
+
/** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
|
|
13
|
+
|
|
11
14
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
|
|
12
15
|
const RESERVED_WORDS = [
|
|
13
16
|
'break',
|
|
@@ -56,62 +59,63 @@ const CONTEXTUAL_KEYWORDS = ['async', 'await', 'let', 'using'];
|
|
|
56
59
|
module.exports = grammar({
|
|
57
60
|
name: 'javascript',
|
|
58
61
|
|
|
59
|
-
externals: (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
externals: () => [
|
|
63
|
+
sym('_automatic_semicolon'),
|
|
64
|
+
sym('_template_chars'),
|
|
65
|
+
sym('_ternary_qmark'),
|
|
66
|
+
sym('html_comment'),
|
|
64
67
|
'||',
|
|
65
68
|
// We use escape sequence and regex pattern to tell the scanner if we're currently inside a string or template string, in which case
|
|
66
69
|
// it should NOT parse html comments.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
sym('escape_sequence'),
|
|
71
|
+
sym('regex_pattern'),
|
|
72
|
+
sym('jsx_text'),
|
|
70
73
|
// Zero-width tokens after an arrow function's block body that a line break (or `}` or the end of input) follows:
|
|
71
74
|
// such a function cannot be called, indexed, or used as an operand, so the statement ends there if it can. The
|
|
72
75
|
// scanner inserts the automatic semicolon right after _arrow_function_block_end, or else emits
|
|
73
76
|
// _arrow_function_block_continuation, since the arrow function may be, e.g., an argument.
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
sym('_arrow_function_block_end'),
|
|
78
|
+
sym('_arrow_function_block_continuation'),
|
|
76
79
|
// These never-emitted flags select LineBreakRule in src/scanner.c. Keep them alternatives to what follows:
|
|
77
80
|
// leading optional flags duplicate parse states.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
sym('_line_break_ends_statement'),
|
|
82
|
+
sym('_line_break_after_binding'),
|
|
83
|
+
sym('_line_break_after_field'),
|
|
84
|
+
sym('_line_break_after_modifier'),
|
|
85
|
+
sym('_line_break_before_attributes'),
|
|
83
86
|
// Emitted outside statement nodes to preserve their body ranges before trailing comments.
|
|
84
|
-
|
|
87
|
+
sym('_statement_boundary'),
|
|
85
88
|
// Await flags are optional exceptions: replacing a required operand with a flag makes its published child optional.
|
|
86
89
|
// Never emitted: marks the direct await operand start for line-break and identifier lexing.
|
|
87
|
-
|
|
90
|
+
sym('_line_break_after_await'),
|
|
88
91
|
// Preserves operand and identifier-statement paths before a following brace or identifier-headed expression.
|
|
89
|
-
|
|
92
|
+
sym('_await_identifier_line_break'),
|
|
90
93
|
// Emitted zero-width boundaries retain canonical expression supertype paths for public queries.
|
|
91
|
-
|
|
94
|
+
sym('_await_operand_end'),
|
|
92
95
|
// Never emitted: a completed direct arrow cannot serve as an await operand.
|
|
93
|
-
|
|
96
|
+
sym('_completed_arrow_function'),
|
|
94
97
|
// Emitted identifier token at the direct await-operand start, preserving normal yield parsing elsewhere.
|
|
95
|
-
|
|
98
|
+
sym('_await_yield_identifier'),
|
|
96
99
|
// Emitted zero-width decision preserves direct operands and identifier statements before yield.
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
sym('_await_yield_identifier_start'),
|
|
101
|
+
sym('_await_yield_identifier_context'),
|
|
99
102
|
// Emitted zero-width after a postfix update; carries the pending statement boundary across reuse.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
sym('_postfix_update_end'),
|
|
104
|
+
sym('_await_keyword'),
|
|
105
|
+
sym('_let'),
|
|
106
|
+
sym('_single_statement_context'),
|
|
107
|
+
sym('_resource_binding_start'),
|
|
108
|
+
sym('_resource_binding_continuation'),
|
|
109
|
+
sym('_plain_resource_for_of_context'),
|
|
110
|
+
sym('_export_default'),
|
|
111
|
+
sym('_export_default_declaration'),
|
|
112
|
+
sym('_default_declaration_start'),
|
|
113
|
+
sym('_regex_flags_start'),
|
|
114
|
+
sym('_argumentless_new_end'),
|
|
115
|
+
sym('_constructor_async_function_start'),
|
|
112
116
|
],
|
|
113
117
|
|
|
114
|
-
extras: ($) => [$.comment,
|
|
118
|
+
extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
|
|
115
119
|
|
|
116
120
|
reserved: {
|
|
117
121
|
global: () => RESERVED_WORDS,
|
|
@@ -206,9 +210,9 @@ module.exports = grammar({
|
|
|
206
210
|
rules: {
|
|
207
211
|
program: ($) => seq(optional($.hash_bang_line), repeat($._statement)),
|
|
208
212
|
|
|
209
|
-
_statement: ($) => prec.right(seq($.statement, optional(
|
|
213
|
+
_statement: ($) => prec.right(seq($.statement, optional(sym('_statement_boundary')))),
|
|
210
214
|
|
|
211
|
-
_single_statement: ($) => seq(optional(
|
|
215
|
+
_single_statement: ($) => seq(optional(sym('_single_statement_context')), $._statement),
|
|
212
216
|
|
|
213
217
|
hash_bang_line: () => /#![^\n\r\u2028\u2029]*/,
|
|
214
218
|
|
|
@@ -224,7 +228,7 @@ module.exports = grammar({
|
|
|
224
228
|
seq(
|
|
225
229
|
choice('*', $.namespace_export, $.export_clause),
|
|
226
230
|
$._from_clause,
|
|
227
|
-
optional(choice($.import_attribute,
|
|
231
|
+
optional(choice($.import_attribute, sym('_line_break_before_attributes')))
|
|
228
232
|
),
|
|
229
233
|
alias($._local_export_clause, $.export_clause)
|
|
230
234
|
),
|
|
@@ -235,10 +239,8 @@ module.exports = grammar({
|
|
|
235
239
|
'export',
|
|
236
240
|
choice(
|
|
237
241
|
field('declaration', $.declaration),
|
|
238
|
-
seq(
|
|
239
|
-
|
|
240
|
-
choice(field('declaration', $.declaration), seq(field('value', $.expression), $._semicolon))
|
|
241
|
-
)
|
|
242
|
+
seq(alias(sym('_export_default_declaration'), 'default'), field('declaration', $.declaration)),
|
|
243
|
+
seq(alias(sym('_export_default'), 'default'), field('value', $.expression), $._semicolon)
|
|
242
244
|
)
|
|
243
245
|
)
|
|
244
246
|
),
|
|
@@ -264,7 +266,10 @@ module.exports = grammar({
|
|
|
264
266
|
$.identifier,
|
|
265
267
|
$.string,
|
|
266
268
|
// `this`, `super`, `true`, `false`, and `null` are named rules, and a bare string would make them non-terminals.
|
|
267
|
-
alias(
|
|
269
|
+
alias(
|
|
270
|
+
choice(...RESERVED_WORDS.map((word) => (NAMED_RESERVED_WORDS.has(word) ? sym(word) : word))),
|
|
271
|
+
$.identifier
|
|
272
|
+
)
|
|
268
273
|
),
|
|
269
274
|
|
|
270
275
|
declaration: ($) =>
|
|
@@ -287,7 +292,7 @@ module.exports = grammar({
|
|
|
287
292
|
seq(
|
|
288
293
|
'import',
|
|
289
294
|
choice(seq($.import_clause, $._from_clause), field('source', $.string)),
|
|
290
|
-
optional(choice($.import_attribute,
|
|
295
|
+
optional(choice($.import_attribute, sym('_line_break_before_attributes'))),
|
|
291
296
|
$._semicolon
|
|
292
297
|
),
|
|
293
298
|
|
|
@@ -353,10 +358,10 @@ module.exports = grammar({
|
|
|
353
358
|
|
|
354
359
|
using_declaration: ($) =>
|
|
355
360
|
seq(
|
|
356
|
-
field('kind', choice('using', seq(alias(
|
|
357
|
-
|
|
361
|
+
field('kind', choice('using', seq(alias(sym('_await_keyword'), 'await'), 'using'))),
|
|
362
|
+
sym('_resource_binding_start'),
|
|
358
363
|
alias($._using_declarator, $.variable_declarator),
|
|
359
|
-
repeat(seq(',',
|
|
364
|
+
repeat(seq(',', sym('_resource_binding_continuation'), alias($._using_declarator, $.variable_declarator))),
|
|
360
365
|
$._semicolon
|
|
361
366
|
),
|
|
362
367
|
|
|
@@ -365,7 +370,7 @@ module.exports = grammar({
|
|
|
365
370
|
variable_declarator: ($) =>
|
|
366
371
|
seq(
|
|
367
372
|
field('name', choice($.identifier, alias('of', $.identifier), $._destructuring_pattern)),
|
|
368
|
-
optional(choice($._initializer,
|
|
373
|
+
optional(choice($._initializer, sym('_line_break_after_binding')))
|
|
369
374
|
),
|
|
370
375
|
|
|
371
376
|
statement_block: ($) => prec.right(seq('{', repeat($._statement), '}')),
|
|
@@ -423,15 +428,15 @@ module.exports = grammar({
|
|
|
423
428
|
|
|
424
429
|
_for_using_declaration: ($) =>
|
|
425
430
|
seq(
|
|
426
|
-
field('kind', choice('using', seq(alias(
|
|
427
|
-
|
|
431
|
+
field('kind', choice('using', seq(alias(sym('_await_keyword'), 'await'), 'using'))),
|
|
432
|
+
sym('_resource_binding_start'),
|
|
428
433
|
alias($._using_declarator, $.variable_declarator),
|
|
429
|
-
repeat(seq(',',
|
|
434
|
+
repeat(seq(',', sym('_resource_binding_continuation'), alias($._using_declarator, $.variable_declarator))),
|
|
430
435
|
';'
|
|
431
436
|
),
|
|
432
437
|
|
|
433
438
|
for_in_statement: ($) =>
|
|
434
|
-
seq('for', optional(alias(
|
|
439
|
+
seq('for', optional(alias(sym('_await_keyword'), 'await')), $._for_header, field('body', $._single_statement)),
|
|
435
440
|
|
|
436
441
|
_for_header: ($) =>
|
|
437
442
|
seq(
|
|
@@ -454,8 +459,11 @@ module.exports = grammar({
|
|
|
454
459
|
),
|
|
455
460
|
seq(
|
|
456
461
|
choice(
|
|
457
|
-
seq(
|
|
458
|
-
|
|
462
|
+
seq(
|
|
463
|
+
field('kind', 'using'),
|
|
464
|
+
choice(sym('_resource_binding_start'), sym('_plain_resource_for_of_context'))
|
|
465
|
+
),
|
|
466
|
+
seq(field('kind', seq(alias(sym('_await_keyword'), 'await'), 'using')), sym('_resource_binding_start'))
|
|
459
467
|
),
|
|
460
468
|
field('left', choice($.identifier, alias('of', $.identifier))),
|
|
461
469
|
field('operator', 'of')
|
|
@@ -492,21 +500,21 @@ module.exports = grammar({
|
|
|
492
500
|
break_statement: ($) =>
|
|
493
501
|
seq(
|
|
494
502
|
'break',
|
|
495
|
-
field('label', optional(alias($.identifier,
|
|
496
|
-
choice($._semicolon,
|
|
503
|
+
field('label', optional(alias($.identifier, sym('statement_identifier')))),
|
|
504
|
+
choice($._semicolon, sym('_line_break_ends_statement'))
|
|
497
505
|
),
|
|
498
506
|
|
|
499
507
|
continue_statement: ($) =>
|
|
500
508
|
seq(
|
|
501
509
|
'continue',
|
|
502
|
-
field('label', optional(alias($.identifier,
|
|
503
|
-
choice($._semicolon,
|
|
510
|
+
field('label', optional(alias($.identifier, sym('statement_identifier')))),
|
|
511
|
+
choice($._semicolon, sym('_line_break_ends_statement'))
|
|
504
512
|
),
|
|
505
513
|
|
|
506
|
-
debugger_statement: ($) => seq('debugger', choice($._semicolon,
|
|
514
|
+
debugger_statement: ($) => seq('debugger', choice($._semicolon, sym('_line_break_ends_statement'))),
|
|
507
515
|
|
|
508
516
|
return_statement: ($) =>
|
|
509
|
-
seq('return', choice(seq(optional($._expressions), $._semicolon),
|
|
517
|
+
seq('return', choice(seq(optional($._expressions), $._semicolon), sym('_line_break_ends_statement'))),
|
|
510
518
|
|
|
511
519
|
throw_statement: ($) => seq('throw', $._expressions, $._semicolon),
|
|
512
520
|
|
|
@@ -514,7 +522,7 @@ module.exports = grammar({
|
|
|
514
522
|
|
|
515
523
|
labeled_statement: ($) =>
|
|
516
524
|
seq(
|
|
517
|
-
field('label', alias(choice($.identifier, $.undefined, $._reserved_identifier),
|
|
525
|
+
field('label', alias(choice($.identifier, $.undefined, $._reserved_identifier), sym('statement_identifier'))),
|
|
518
526
|
':',
|
|
519
527
|
field('body', $._single_statement)
|
|
520
528
|
),
|
|
@@ -563,7 +571,7 @@ module.exports = grammar({
|
|
|
563
571
|
$._jsx_element,
|
|
564
572
|
$.parenthesized_expression,
|
|
565
573
|
$._identifier,
|
|
566
|
-
alias(
|
|
574
|
+
alias(sym('_await_yield_identifier'), $.identifier),
|
|
567
575
|
alias($._reserved_identifier, $.identifier),
|
|
568
576
|
$.this,
|
|
569
577
|
$.super,
|
|
@@ -589,7 +597,9 @@ module.exports = grammar({
|
|
|
589
597
|
),
|
|
590
598
|
|
|
591
599
|
yield_expression: ($) =>
|
|
592
|
-
prec.right(
|
|
600
|
+
prec.right(
|
|
601
|
+
seq('yield', choice(seq('*', $.expression), optional($.expression), sym('_line_break_ends_statement')))
|
|
602
|
+
),
|
|
593
603
|
|
|
594
604
|
object: ($) =>
|
|
595
605
|
prec(
|
|
@@ -602,7 +612,7 @@ module.exports = grammar({
|
|
|
602
612
|
$.pair,
|
|
603
613
|
$.spread_element,
|
|
604
614
|
$.method_definition,
|
|
605
|
-
alias(choice($.identifier, $._reserved_identifier),
|
|
615
|
+
alias(choice($.identifier, $._reserved_identifier), sym('shorthand_property_identifier'))
|
|
606
616
|
)
|
|
607
617
|
)
|
|
608
618
|
),
|
|
@@ -621,7 +631,7 @@ module.exports = grammar({
|
|
|
621
631
|
$.pair_pattern,
|
|
622
632
|
$.rest_pattern,
|
|
623
633
|
$.object_assignment_pattern,
|
|
624
|
-
alias(choice($.identifier, $._reserved_identifier),
|
|
634
|
+
alias(choice($.identifier, $._reserved_identifier), sym('shorthand_property_identifier_pattern'))
|
|
625
635
|
)
|
|
626
636
|
)
|
|
627
637
|
),
|
|
@@ -636,7 +646,7 @@ module.exports = grammar({
|
|
|
636
646
|
field(
|
|
637
647
|
'left',
|
|
638
648
|
choice(
|
|
639
|
-
alias(choice($._reserved_identifier, $.identifier),
|
|
649
|
+
alias(choice($._reserved_identifier, $.identifier), sym('shorthand_property_identifier_pattern')),
|
|
640
650
|
$._destructuring_pattern
|
|
641
651
|
)
|
|
642
652
|
),
|
|
@@ -660,7 +670,7 @@ module.exports = grammar({
|
|
|
660
670
|
|
|
661
671
|
jsx_expression: ($) => seq('{', optional(choice($.expression, $.sequence_expression, $.spread_element)), '}'),
|
|
662
672
|
|
|
663
|
-
_jsx_child: ($) => choice(
|
|
673
|
+
_jsx_child: ($) => choice(sym('jsx_text'), $.html_character_reference, $._jsx_element, $.jsx_expression),
|
|
664
674
|
|
|
665
675
|
jsx_opening_element: ($) =>
|
|
666
676
|
prec.dynamic(
|
|
@@ -681,7 +691,7 @@ module.exports = grammar({
|
|
|
681
691
|
choice(reserved('properties', $.identifier), alias($.nested_identifier, $.member_expression))
|
|
682
692
|
),
|
|
683
693
|
'.',
|
|
684
|
-
field('property', alias(reserved('properties', $.identifier),
|
|
694
|
+
field('property', alias(reserved('properties', $.identifier), sym('property_identifier')))
|
|
685
695
|
)
|
|
686
696
|
),
|
|
687
697
|
|
|
@@ -697,7 +707,7 @@ module.exports = grammar({
|
|
|
697
707
|
|
|
698
708
|
_jsx_attribute: ($) => choice($.jsx_attribute, $.jsx_expression),
|
|
699
709
|
|
|
700
|
-
_jsx_attribute_name: ($) => choice(alias($._jsx_identifier,
|
|
710
|
+
_jsx_attribute_name: ($) => choice(alias($._jsx_identifier, sym('property_identifier')), $.jsx_namespace_name),
|
|
701
711
|
|
|
702
712
|
jsx_attribute: ($) => seq($._jsx_attribute_name, optional(seq('=', $._jsx_attribute_value))),
|
|
703
713
|
|
|
@@ -707,9 +717,9 @@ module.exports = grammar({
|
|
|
707
717
|
'"',
|
|
708
718
|
repeat(
|
|
709
719
|
choice(
|
|
710
|
-
alias($.unescaped_double_jsx_string_fragment,
|
|
720
|
+
alias($.unescaped_double_jsx_string_fragment, sym('string_fragment')),
|
|
711
721
|
$.html_character_reference,
|
|
712
|
-
alias($._jsx_string_ampersand,
|
|
722
|
+
alias($._jsx_string_ampersand, sym('string_fragment'))
|
|
713
723
|
)
|
|
714
724
|
),
|
|
715
725
|
'"'
|
|
@@ -718,9 +728,9 @@ module.exports = grammar({
|
|
|
718
728
|
"'",
|
|
719
729
|
repeat(
|
|
720
730
|
choice(
|
|
721
|
-
alias($.unescaped_single_jsx_string_fragment,
|
|
731
|
+
alias($.unescaped_single_jsx_string_fragment, sym('string_fragment')),
|
|
722
732
|
$.html_character_reference,
|
|
723
|
-
alias($._jsx_string_ampersand,
|
|
733
|
+
alias($._jsx_string_ampersand, sym('string_fragment'))
|
|
724
734
|
)
|
|
725
735
|
),
|
|
726
736
|
"'"
|
|
@@ -760,7 +770,7 @@ module.exports = grammar({
|
|
|
760
770
|
seq(
|
|
761
771
|
choice(
|
|
762
772
|
seq(
|
|
763
|
-
|
|
773
|
+
sym('_default_declaration_start'),
|
|
764
774
|
repeat(field('decorator', $.decorator)),
|
|
765
775
|
'class',
|
|
766
776
|
field('name', optional($.identifier))
|
|
@@ -791,7 +801,12 @@ module.exports = grammar({
|
|
|
791
801
|
'declaration',
|
|
792
802
|
seq(
|
|
793
803
|
choice(
|
|
794
|
-
seq(
|
|
804
|
+
seq(
|
|
805
|
+
sym('_default_declaration_start'),
|
|
806
|
+
optional('async'),
|
|
807
|
+
'function',
|
|
808
|
+
field('name', optional($.identifier))
|
|
809
|
+
),
|
|
795
810
|
seq(optional('async'), 'function', field('name', $.identifier))
|
|
796
811
|
),
|
|
797
812
|
$._call_signature,
|
|
@@ -818,7 +833,7 @@ module.exports = grammar({
|
|
|
818
833
|
seq(
|
|
819
834
|
choice(
|
|
820
835
|
seq(
|
|
821
|
-
|
|
836
|
+
sym('_default_declaration_start'),
|
|
822
837
|
optional('async'),
|
|
823
838
|
'function',
|
|
824
839
|
'*',
|
|
@@ -847,10 +862,10 @@ module.exports = grammar({
|
|
|
847
862
|
field('body', $.expression),
|
|
848
863
|
seq(
|
|
849
864
|
field('body', $.statement_block),
|
|
850
|
-
optional(seq(
|
|
865
|
+
optional(seq(sym('_arrow_function_block_end'), optional(sym('_arrow_function_block_continuation'))))
|
|
851
866
|
)
|
|
852
867
|
),
|
|
853
|
-
optional(
|
|
868
|
+
optional(sym('_completed_arrow_function'))
|
|
854
869
|
)
|
|
855
870
|
),
|
|
856
871
|
|
|
@@ -884,7 +899,7 @@ module.exports = grammar({
|
|
|
884
899
|
prec(
|
|
885
900
|
'literal',
|
|
886
901
|
seq(
|
|
887
|
-
optional(
|
|
902
|
+
optional(sym('_constructor_async_function_start')),
|
|
888
903
|
optional('async'),
|
|
889
904
|
'function',
|
|
890
905
|
field('name', optional($.identifier)),
|
|
@@ -897,7 +912,7 @@ module.exports = grammar({
|
|
|
897
912
|
prec(
|
|
898
913
|
'literal',
|
|
899
914
|
seq(
|
|
900
|
-
optional(
|
|
915
|
+
optional(sym('_constructor_async_function_start')),
|
|
901
916
|
optional('async'),
|
|
902
917
|
'function',
|
|
903
918
|
'*',
|
|
@@ -912,7 +927,7 @@ module.exports = grammar({
|
|
|
912
927
|
$._jsx_element,
|
|
913
928
|
$.parenthesized_expression,
|
|
914
929
|
$._identifier,
|
|
915
|
-
alias(
|
|
930
|
+
alias(sym('_await_yield_identifier'), $.identifier),
|
|
916
931
|
alias($._reserved_identifier, $.identifier),
|
|
917
932
|
$.this,
|
|
918
933
|
$.super,
|
|
@@ -954,7 +969,10 @@ module.exports = grammar({
|
|
|
954
969
|
'.',
|
|
955
970
|
field(
|
|
956
971
|
'property',
|
|
957
|
-
choice(
|
|
972
|
+
choice(
|
|
973
|
+
$.private_property_identifier,
|
|
974
|
+
reserved('properties', alias($.identifier, sym('property_identifier')))
|
|
975
|
+
)
|
|
958
976
|
)
|
|
959
977
|
)
|
|
960
978
|
),
|
|
@@ -982,7 +1000,7 @@ module.exports = grammar({
|
|
|
982
1000
|
_argumentless_new_expression: ($) =>
|
|
983
1001
|
prec.right(
|
|
984
1002
|
'new',
|
|
985
|
-
seq('new', field('constructor', alias($._constructor, $.primary_expression)),
|
|
1003
|
+
seq('new', field('constructor', alias($._constructor, $.primary_expression)), sym('_argumentless_new_end'))
|
|
986
1004
|
),
|
|
987
1005
|
|
|
988
1006
|
await_expression: ($) =>
|
|
@@ -991,17 +1009,17 @@ module.exports = grammar({
|
|
|
991
1009
|
prec.right(
|
|
992
1010
|
'unary_void',
|
|
993
1011
|
seq(
|
|
994
|
-
alias(
|
|
1012
|
+
alias(sym('_await_keyword'), 'await'),
|
|
995
1013
|
// Independent optional prefixes duplicate parser states; the yield start/context pair stays one alternative.
|
|
996
1014
|
optional(
|
|
997
1015
|
choice(
|
|
998
|
-
|
|
999
|
-
seq(
|
|
1000
|
-
|
|
1016
|
+
sym('_await_identifier_line_break'),
|
|
1017
|
+
seq(sym('_await_yield_identifier_start'), optional(sym('_await_yield_identifier_context'))),
|
|
1018
|
+
sym('_line_break_after_await')
|
|
1001
1019
|
)
|
|
1002
1020
|
),
|
|
1003
1021
|
$.expression,
|
|
1004
|
-
|
|
1022
|
+
sym('_await_operand_end')
|
|
1005
1023
|
)
|
|
1006
1024
|
)
|
|
1007
1025
|
),
|
|
@@ -1014,7 +1032,10 @@ module.exports = grammar({
|
|
|
1014
1032
|
choice('.', field('optional_chain', $.optional_chain)),
|
|
1015
1033
|
field(
|
|
1016
1034
|
'property',
|
|
1017
|
-
choice(
|
|
1035
|
+
choice(
|
|
1036
|
+
$.private_property_identifier,
|
|
1037
|
+
reserved('properties', alias($.identifier, sym('property_identifier')))
|
|
1038
|
+
)
|
|
1018
1039
|
)
|
|
1019
1040
|
)
|
|
1020
1041
|
),
|
|
@@ -1079,7 +1100,7 @@ module.exports = grammar({
|
|
|
1079
1100
|
'ternary',
|
|
1080
1101
|
seq(
|
|
1081
1102
|
field('condition', $.expression),
|
|
1082
|
-
alias(
|
|
1103
|
+
alias(sym('_ternary_qmark'), '?'),
|
|
1083
1104
|
field('consequence', $.expression),
|
|
1084
1105
|
':',
|
|
1085
1106
|
field('alternative', $.expression)
|
|
@@ -1088,7 +1109,7 @@ module.exports = grammar({
|
|
|
1088
1109
|
|
|
1089
1110
|
binary_expression: ($) =>
|
|
1090
1111
|
choice(
|
|
1091
|
-
|
|
1112
|
+
.../** @type {const} */ ([
|
|
1092
1113
|
['&&', 'logical_and'],
|
|
1093
1114
|
['||', 'logical_or'],
|
|
1094
1115
|
['>>', 'binary_shift'],
|
|
@@ -1114,7 +1135,7 @@ module.exports = grammar({
|
|
|
1114
1135
|
['??', 'ternary'],
|
|
1115
1136
|
['instanceof', 'binary_relation'],
|
|
1116
1137
|
['in', 'binary_relation'],
|
|
1117
|
-
].map(([operator, precedence, associativity]) =>
|
|
1138
|
+
]).map(([operator, precedence, associativity]) =>
|
|
1118
1139
|
// oxlint-disable-next-line typescript/unbound-method -- prec.left and prec.right do not use `this`.
|
|
1119
1140
|
(associativity === 'right' ? prec.right : prec.left)(
|
|
1120
1141
|
precedence,
|
|
@@ -1136,7 +1157,7 @@ module.exports = grammar({
|
|
|
1136
1157
|
update_expression: ($) =>
|
|
1137
1158
|
prec.left(
|
|
1138
1159
|
choice(
|
|
1139
|
-
seq(field('argument', $.expression), field('operator', choice('++', '--')),
|
|
1160
|
+
seq(field('argument', $.expression), field('operator', choice('++', '--')), sym('_postfix_update_end')),
|
|
1140
1161
|
seq(field('operator', choice('++', '--')), field('argument', $.expression))
|
|
1141
1162
|
)
|
|
1142
1163
|
),
|
|
@@ -1149,8 +1170,16 @@ module.exports = grammar({
|
|
|
1149
1170
|
|
|
1150
1171
|
string: ($) =>
|
|
1151
1172
|
choice(
|
|
1152
|
-
seq(
|
|
1153
|
-
|
|
1173
|
+
seq(
|
|
1174
|
+
'"',
|
|
1175
|
+
repeat(choice(alias($.unescaped_double_string_fragment, sym('string_fragment')), $.escape_sequence)),
|
|
1176
|
+
'"'
|
|
1177
|
+
),
|
|
1178
|
+
seq(
|
|
1179
|
+
"'",
|
|
1180
|
+
repeat(choice(alias($.unescaped_single_string_fragment, sym('string_fragment')), $.escape_sequence)),
|
|
1181
|
+
"'"
|
|
1182
|
+
)
|
|
1154
1183
|
),
|
|
1155
1184
|
|
|
1156
1185
|
// Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
|
|
@@ -1175,7 +1204,7 @@ module.exports = grammar({
|
|
|
1175
1204
|
'`',
|
|
1176
1205
|
repeat(
|
|
1177
1206
|
choice(
|
|
1178
|
-
alias(
|
|
1207
|
+
alias(sym('_template_chars'), sym('string_fragment')),
|
|
1179
1208
|
$.escape_sequence,
|
|
1180
1209
|
alias($._invalid_template_escape, $.escape_sequence),
|
|
1181
1210
|
$.template_substitution
|
|
@@ -1196,7 +1225,7 @@ module.exports = grammar({
|
|
|
1196
1225
|
'/',
|
|
1197
1226
|
field('pattern', $.regex_pattern),
|
|
1198
1227
|
choice(
|
|
1199
|
-
seq(
|
|
1228
|
+
seq(sym('_regex_flags_start'), token.immediate(prec(1, '/')), field('flags', $.regex_flags)),
|
|
1200
1229
|
token.immediate(prec(1, '/'))
|
|
1201
1230
|
)
|
|
1202
1231
|
),
|
|
@@ -1318,7 +1347,10 @@ module.exports = grammar({
|
|
|
1318
1347
|
'.',
|
|
1319
1348
|
field(
|
|
1320
1349
|
'property',
|
|
1321
|
-
choice(
|
|
1350
|
+
choice(
|
|
1351
|
+
reserved('properties', alias($.identifier, sym('property_identifier'))),
|
|
1352
|
+
$.private_property_identifier
|
|
1353
|
+
)
|
|
1322
1354
|
)
|
|
1323
1355
|
)
|
|
1324
1356
|
),
|
|
@@ -1356,24 +1388,24 @@ module.exports = grammar({
|
|
|
1356
1388
|
seq(
|
|
1357
1389
|
optional('static'),
|
|
1358
1390
|
choice(
|
|
1359
|
-
seq(field('property', $._field_name), optional(choice($._initializer,
|
|
1391
|
+
seq(field('property', $._field_name), optional(choice($._initializer, sym('_line_break_after_field')))),
|
|
1360
1392
|
// A line break after `get` or `set` continues a getter or setter. Allowing both sentinels here tells
|
|
1361
1393
|
// the scanner that a `*` on the next line cannot continue the member, unlike after `static`.
|
|
1362
1394
|
seq(
|
|
1363
|
-
field('property', alias(choice('get', 'set'),
|
|
1364
|
-
optional(choice($._initializer,
|
|
1395
|
+
field('property', alias(choice('get', 'set'), sym('property_identifier'))),
|
|
1396
|
+
optional(choice($._initializer, sym('_line_break_after_modifier'), sym('_line_break_after_field')))
|
|
1365
1397
|
)
|
|
1366
1398
|
)
|
|
1367
1399
|
),
|
|
1368
1400
|
// A line break after a leading `static` continues a static member; after `static static`, it ends the field.
|
|
1369
1401
|
seq(
|
|
1370
|
-
field('property', alias('static',
|
|
1371
|
-
optional(choice($._initializer,
|
|
1402
|
+
field('property', alias('static', sym('property_identifier'))),
|
|
1403
|
+
optional(choice($._initializer, sym('_line_break_after_modifier')))
|
|
1372
1404
|
),
|
|
1373
1405
|
seq(
|
|
1374
1406
|
'static',
|
|
1375
|
-
field('property', alias('static',
|
|
1376
|
-
optional(choice($._initializer,
|
|
1407
|
+
field('property', alias('static', sym('property_identifier'))),
|
|
1408
|
+
optional(choice($._initializer, sym('_line_break_after_field')))
|
|
1377
1409
|
)
|
|
1378
1410
|
)
|
|
1379
1411
|
),
|
|
@@ -1415,8 +1447,11 @@ module.exports = grammar({
|
|
|
1415
1447
|
'properties',
|
|
1416
1448
|
choice(
|
|
1417
1449
|
alias(
|
|
1418
|
-
choice(
|
|
1419
|
-
|
|
1450
|
+
choice(
|
|
1451
|
+
$.identifier,
|
|
1452
|
+
...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? sym('_await_keyword') : word))
|
|
1453
|
+
),
|
|
1454
|
+
sym('property_identifier')
|
|
1420
1455
|
),
|
|
1421
1456
|
$.private_property_identifier,
|
|
1422
1457
|
$.string,
|
|
@@ -1429,7 +1464,7 @@ module.exports = grammar({
|
|
|
1429
1464
|
reserved(
|
|
1430
1465
|
'properties',
|
|
1431
1466
|
choice(
|
|
1432
|
-
alias(choice($.identifier, $._reserved_identifier),
|
|
1467
|
+
alias(choice($.identifier, $._reserved_identifier), sym('property_identifier')),
|
|
1433
1468
|
$.private_property_identifier,
|
|
1434
1469
|
$.string,
|
|
1435
1470
|
$.number,
|
|
@@ -1439,20 +1474,28 @@ module.exports = grammar({
|
|
|
1439
1474
|
|
|
1440
1475
|
computed_property_name: ($) => seq('[', $.expression, ']'),
|
|
1441
1476
|
|
|
1442
|
-
_reserved_identifier: (
|
|
1443
|
-
choice(
|
|
1477
|
+
_reserved_identifier: () =>
|
|
1478
|
+
choice(
|
|
1479
|
+
...MEMBER_MODIFIERS,
|
|
1480
|
+
...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? sym('_await_keyword') : word))
|
|
1481
|
+
),
|
|
1444
1482
|
|
|
1445
|
-
_semicolon: (
|
|
1446
|
-
choice(
|
|
1483
|
+
_semicolon: () =>
|
|
1484
|
+
choice(
|
|
1485
|
+
sym('_automatic_semicolon'),
|
|
1486
|
+
sym('_await_identifier_line_break'),
|
|
1487
|
+
sym('_await_yield_identifier_start'),
|
|
1488
|
+
';'
|
|
1489
|
+
),
|
|
1447
1490
|
},
|
|
1448
1491
|
});
|
|
1449
1492
|
|
|
1450
1493
|
/**
|
|
1451
1494
|
* Creates a rule to match one or more of the rules separated by a comma
|
|
1452
1495
|
*
|
|
1453
|
-
* @param {
|
|
1496
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
1454
1497
|
*
|
|
1455
|
-
* @returns {SeqRule}
|
|
1498
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
1456
1499
|
*/
|
|
1457
1500
|
function commaSep1(rule) {
|
|
1458
1501
|
return seq(rule, repeat(seq(',', rule)));
|
|
@@ -1461,9 +1504,9 @@ function commaSep1(rule) {
|
|
|
1461
1504
|
/**
|
|
1462
1505
|
* Creates a rule to optionally match one or more of the rules separated by a comma
|
|
1463
1506
|
*
|
|
1464
|
-
* @param {
|
|
1507
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
1465
1508
|
*
|
|
1466
|
-
* @returns {ChoiceRule}
|
|
1509
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
1467
1510
|
*/
|
|
1468
1511
|
function commaSep(rule) {
|
|
1469
1512
|
return optional(commaSep1(rule));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-javascript",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "JavaScript grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"playwright": "1.63.0",
|
|
57
57
|
"semantic-release": "25.0.9",
|
|
58
58
|
"sort-package-json": "4.0.0",
|
|
59
|
-
"tree-sitter-cli": "0.27.0",
|
|
60
59
|
"typescript": "7.0.2",
|
|
61
60
|
"vite": "8.3.2",
|
|
62
61
|
"vitest": "5.0.3",
|
|
Binary file
|