@willbooster/tree-sitter-javascript 14.0.0 → 15.0.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/grammar.js CHANGED
@@ -147,6 +147,8 @@ module.exports = grammar({
147
147
  $._unary_operand,
148
148
  $.primary_expression,
149
149
  $.pattern,
150
+ $._non_rest_pattern,
151
+ $._rest_pattern,
150
152
  $._constructor,
151
153
  $._constructor_chain_base,
152
154
  $._assignment_call_callee,
@@ -214,30 +216,23 @@ module.exports = grammar({
214
216
 
215
217
  conflicts: ($) => [
216
218
  [$._primary_atom, $._simple_target_primary],
217
- [$._simple_target_primary, $.pattern],
218
- [$._primary_atom, $._simple_target_primary, $.pattern],
219
+ [$._simple_target_primary, $._non_rest_pattern],
220
+ [$._primary_atom, $._simple_target_primary, $._non_rest_pattern],
219
221
  [$._call_callee, $.call_expression],
220
222
  [$.for_in_clause, $._primary_atom],
221
223
  [$._primary_atom, $.rest_pattern],
222
- [$._primary_atom, $.pattern],
223
- [$.arrow_function, $._primary_atom, $._property_name],
224
- [$._primary_atom, $.method_definition],
225
- [$._primary_atom, $._property_name],
226
- [$._primary_atom, $.await_expression, $._property_name],
227
- [$.object, $.object_pattern, $._primary_atom],
224
+ [$._primary_atom, $._non_rest_pattern],
228
225
  [$.arrow_function, $._primary_atom],
229
226
  [$._primary_atom, $.await_expression],
230
227
  [$.call_expression, $._constructor_import],
231
228
  [$.primary_expression, $._assignment_call_primary],
232
229
  [$._local_export_specifier, $._module_export_name],
233
230
  [$.primary_expression, $.rest_pattern],
234
- [$.primary_expression, $.pattern],
231
+ [$.primary_expression, $._non_rest_pattern],
235
232
  [$.primary_expression, $.for_in_clause],
236
233
  [$.array, $.array_pattern],
237
234
  [$.object, $.object_pattern],
238
- [$.assignment_expression, $.pattern],
239
- [$.assignment_expression, $.object_assignment_pattern],
240
- [$.computed_property_name, $.array],
235
+ [$.assignment_expression, $._non_rest_pattern],
241
236
  ],
242
237
 
243
238
  word: ($) => $.identifier,
@@ -449,7 +444,7 @@ module.exports = grammar({
449
444
  optional($._initializer)
450
445
  ),
451
446
 
452
- statement_block: ($) => prec.right(seq('{', repeat($._statement), '}')),
447
+ statement_block: ($) => prec.right(seq(token(prec(1, '{')), repeat($._statement), '}')),
453
448
 
454
449
  else_clause: ($) => seq('else', $._single_statement),
455
450
 
@@ -707,29 +702,23 @@ module.exports = grammar({
707
702
  )
708
703
  ),
709
704
 
710
- object_pattern: ($) =>
711
- prec(
712
- 'object',
713
- seq(
714
- '{',
715
- commaSep(
716
- optional(
717
- choice(
718
- $.pair_pattern,
719
- $.rest_pattern,
720
- $.object_assignment_pattern,
721
- aliasWithAsyncKeyword(
722
- choice($.identifier, $._reserved_identifier),
723
- sym('shorthand_property_identifier_pattern')
724
- )
725
- )
726
- )
727
- ),
728
- '}'
705
+ object_pattern: ($) => {
706
+ const property = choice(
707
+ $.pair_pattern,
708
+ $.object_assignment_pattern,
709
+ aliasWithAsyncKeyword(
710
+ choice($.identifier, $._reserved_identifier),
711
+ sym('shorthand_property_identifier_pattern')
729
712
  )
730
- ),
713
+ );
714
+ return prec(
715
+ 'object',
716
+ seq('{', repeat(seq(optional(property), ',')), optional(choice(property, $.rest_pattern)), '}')
717
+ );
718
+ },
731
719
 
732
- assignment_pattern: ($) => seq(field('left', $.pattern), '=', field('right', $.expression)),
720
+ assignment_pattern: ($) =>
721
+ seq(field('left', alias($._non_rest_pattern, $.pattern)), '=', field('right', $.expression)),
733
722
 
734
723
  object_assignment_pattern: ($) =>
735
724
  seq(
@@ -749,7 +738,13 @@ module.exports = grammar({
749
738
 
750
739
  array: ($) => seq('[', commaSep(optional(choice($.expression, $.spread_element))), ']'),
751
740
 
752
- array_pattern: ($) => seq('[', commaSep(optional(choice($.pattern, $.assignment_pattern))), ']'),
741
+ array_pattern: ($) =>
742
+ seq(
743
+ '[',
744
+ repeat(seq(optional(choice(alias($._non_rest_pattern, $.pattern), $.assignment_pattern)), ',')),
745
+ optional(choice($.pattern, $.assignment_pattern)),
746
+ ']'
747
+ ),
753
748
 
754
749
  _jsx_element: ($) => choice($.jsx_element, $.jsx_self_closing_element),
755
750
 
@@ -979,9 +974,10 @@ module.exports = grammar({
979
974
  )
980
975
  ),
981
976
 
982
- // Override
983
977
  _call_signature: ($) => field('parameters', $.formal_parameters),
984
- _formal_parameter: ($) => choice($.pattern, $.assignment_pattern),
978
+
979
+ /** Ordinary, comma-permitted parameters. Overrides must exclude rest forms. */
980
+ _formal_parameter: ($) => choice(alias($._non_rest_pattern, $.pattern), $.assignment_pattern),
985
981
 
986
982
  _call_callee: ($) => $.primary_expression,
987
983
 
@@ -1662,18 +1658,27 @@ module.exports = grammar({
1662
1658
  _field_initializer: ($) =>
1663
1659
  seq('=', sym('_sync_function_start'), field('value', $.expression), sym('_arrow_context_end')),
1664
1660
 
1665
- formal_parameters: ($) => seq('(', optional(seq(commaSep1($._formal_parameter), optional(','))), ')'),
1661
+ formal_parameters: ($) =>
1662
+ seq(
1663
+ '(',
1664
+ repeat(seq($._formal_parameter, ',')),
1665
+ optional(choice($._formal_parameter, alias($._rest_pattern, $.pattern))),
1666
+ ')'
1667
+ ),
1666
1668
 
1667
1669
  class_static_block: ($) => seq('static', field('body', alias($._class_member_body, $.statement_block))),
1668
1670
 
1669
- // This negative dynamic precedence ensures that during error recovery,
1670
- // unfinished constructs are generally treated as literal expressions,
1671
- // not patterns.
1672
- pattern: ($) =>
1673
- prec.dynamic(
1674
- -1,
1675
- choice($._lhs_expression, alias($._parenthesized_simple_target, $.parenthesized_expression), $.rest_pattern)
1676
- ),
1671
+ /**
1672
+ * Canonical pattern supertype. Extend `_non_rest_pattern` for non-rest forms and
1673
+ * `rest_pattern` for rest syntax; overriding only `pattern` does not extend ordinary slots.
1674
+ */
1675
+ pattern: ($) => choice(alias($._non_rest_pattern, $.pattern), alias($._rest_pattern, $.pattern)),
1676
+
1677
+ // Prefer expression forms over both pattern routes during ambiguous error recovery.
1678
+ _non_rest_pattern: ($) =>
1679
+ prec.dynamic(-1, choice($._lhs_expression, alias($._parenthesized_simple_target, $.parenthesized_expression))),
1680
+
1681
+ _rest_pattern: ($) => prec.dynamic(-1, $.rest_pattern),
1677
1682
 
1678
1683
  rest_pattern: ($) =>
1679
1684
  prec.right(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "14.0.0",
3
+ "version": "15.0.0",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -48,7 +48,7 @@
48
48
  }
49
49
  ],
50
50
  "metadata": {
51
- "version": "14.0.0",
51
+ "version": "15.0.0",
52
52
  "license": "MIT",
53
53
  "description": "JavaScript grammar for tree-sitter",
54
54
  "authors": [