@willbooster/tree-sitter-javascript 5.0.0 → 5.0.1

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