@willbooster/tree-sitter-javascript 22.0.0 → 22.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
@@ -233,7 +233,6 @@ module.exports = grammar({
233
233
  [$._primary_atom, $._simple_target_primary],
234
234
  [$._simple_target_primary, $._non_rest_pattern],
235
235
  [$._primary_atom, $._simple_target_primary, $._non_rest_pattern],
236
- [$._call_callee, $.call_expression],
237
236
  [$._class_heritage_expression, $._class_heritage_call],
238
237
  [$.for_in_clause, $._primary_atom],
239
238
  [$._primary_atom, $.rest_pattern],
@@ -241,13 +240,17 @@ module.exports = grammar({
241
240
  [$._primary_atom, $._non_rest_pattern],
242
241
  [$.arrow_function, $._primary_atom],
243
242
  [$._primary_atom, $.await_expression],
244
- [$.call_expression, $._constructor_import],
245
- [$.primary_expression, $._assignment_call_primary],
243
+ [$._assignment_call_primary, $._classic_call_target],
244
+ [$._assignment_call_primary, $._simple_target_primary, $._non_rest_pattern],
245
+ [$._non_assignment_call_primary, $._non_rest_pattern],
246
+ [$._non_assignment_call_primary, $._object_rest_pattern],
247
+ [$.for_in_clause, $._non_assignment_call_primary],
248
+ [$._non_assignment_call_primary, $.rest_pattern],
246
249
  [$._local_export_specifier, $._module_export_name],
247
- [$.primary_expression, $.rest_pattern],
248
- [$.primary_expression, $._object_rest_pattern],
249
- [$.primary_expression, $._non_rest_pattern],
250
- [$.primary_expression, $.for_in_clause],
250
+ [$._assignment_call_primary, $.rest_pattern],
251
+ [$._assignment_call_primary, $._object_rest_pattern],
252
+ [$._assignment_call_primary, $._non_rest_pattern],
253
+ [$._assignment_call_primary, $.for_in_clause],
251
254
  [$.array, $.array_pattern],
252
255
  [$.object, $.object_pattern],
253
256
  [$.assignment_expression, $._non_rest_pattern],
@@ -661,7 +664,14 @@ module.exports = grammar({
661
664
 
662
665
  _unary_operand: ($) => choice($.primary_expression, $.await_expression, $.unary_expression, $.update_expression),
663
666
 
664
- primary_expression: ($) => choice(leftHandSideExpression($), $.arrow_function),
667
+ // Calls in `_assignment_call_primary` chains can be classic call assignment targets; the other chains contain an
668
+ // optional chain or start with an arrow function. Keeping the two disjoint lets the tokens read so far decide every
669
+ // chain, where overlapping chains would split the parse at every call until its arguments end.
670
+ primary_expression: ($) =>
671
+ choice(alias($._assignment_call_primary, $.primary_expression), $._non_assignment_call_primary),
672
+
673
+ _non_assignment_call_primary: ($) =>
674
+ choice($.member_expression, $.subscript_expression, $.call_expression, $.arrow_function),
665
675
 
666
676
  yield_expression: ($) =>
667
677
  prec.right(
@@ -859,12 +869,14 @@ module.exports = grammar({
859
869
  _class_heritage_expression: ($) => alias($._class_heritage_primary, $.primary_expression),
860
870
 
861
871
  _class_heritage_primary: ($) =>
862
- leftHandSideExpression($, {
863
- atom: $._class_heritage_atom,
864
- call: alias($._class_heritage_call, $.call_expression),
865
- member: alias($._class_heritage_member, $.member_expression),
866
- subscript: alias($._class_heritage_subscript, $.subscript_expression),
867
- }),
872
+ choice(
873
+ $._class_heritage_atom,
874
+ alias($._class_heritage_subscript, $.subscript_expression),
875
+ alias($._class_heritage_member, $.member_expression),
876
+ alias($._class_heritage_call, $.call_expression),
877
+ $.new_expression,
878
+ alias($._argumentless_new_expression, $.new_expression)
879
+ ),
868
880
 
869
881
  _class_heritage_atom: ($) => primaryAtom($, $._expression_identifier),
870
882
 
@@ -994,7 +1006,25 @@ module.exports = grammar({
994
1006
 
995
1007
  optional_chain: () => '?.',
996
1008
 
997
- call_expression: ($) => callExpression($, alias($._call_callee, $.expression), $.primary_expression),
1009
+ call_expression: ($) =>
1010
+ choice(
1011
+ prec('call', seq(field('function', $._non_assignment_call_primary), field('arguments', $.arguments))),
1012
+ prec(
1013
+ 'template_call',
1014
+ seq(
1015
+ field('function', $._non_assignment_call_primary),
1016
+ field('arguments', alias($._tagged_template_string, $.template_string))
1017
+ )
1018
+ ),
1019
+ prec(
1020
+ 'member',
1021
+ seq(
1022
+ field('function', alias($._call_callee, $.expression)),
1023
+ field('optional_chain', $.optional_chain),
1024
+ field('arguments', $.arguments)
1025
+ )
1026
+ )
1027
+ ),
998
1028
 
999
1029
  _primary_atom: ($) => primaryAtom($, $._reserved_identifier),
1000
1030
 
@@ -1186,14 +1216,47 @@ module.exports = grammar({
1186
1216
  )
1187
1217
  ),
1188
1218
 
1189
- member_expression: ($) => memberExpression($, alias($._call_callee, $.expression)),
1219
+ member_expression: ($) =>
1220
+ prec(
1221
+ 'member',
1222
+ seq(
1223
+ choice(
1224
+ seq(
1225
+ field('object', choice(alias($._call_callee, $.expression), $.import)),
1226
+ field('optional_chain', $.optional_chain)
1227
+ ),
1228
+ seq(field('object', choice($._non_assignment_call_primary, $.import)), '.')
1229
+ ),
1230
+ field(
1231
+ 'property',
1232
+ choice(
1233
+ $.private_property_identifier,
1234
+ reserved('properties', alias($.identifier, sym('property_identifier')))
1235
+ )
1236
+ )
1237
+ )
1238
+ ),
1190
1239
 
1191
- subscript_expression: ($) => subscriptExpression($, alias($._call_callee, $.expression)),
1240
+ subscript_expression: ($) =>
1241
+ prec.right(
1242
+ 'member',
1243
+ seq(
1244
+ choice(
1245
+ seq(field('object', alias($._call_callee, $.expression)), field('optional_chain', $.optional_chain)),
1246
+ field('object', $._non_assignment_call_primary)
1247
+ ),
1248
+ '[',
1249
+ field('index', $._expressions),
1250
+ ']'
1251
+ )
1252
+ ),
1192
1253
 
1193
1254
  _lhs_expression: ($) =>
1194
1255
  choice(
1195
1256
  $.member_expression,
1196
1257
  $.subscript_expression,
1258
+ alias($._assignment_member, $.member_expression),
1259
+ alias($._assignment_subscript, $.subscript_expression),
1197
1260
  $._identifier,
1198
1261
  aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1199
1262
  $._destructuring_pattern
@@ -1246,6 +1309,8 @@ module.exports = grammar({
1246
1309
  choice(
1247
1310
  $.member_expression,
1248
1311
  $.subscript_expression,
1312
+ alias($._assignment_member, $.member_expression),
1313
+ alias($._assignment_subscript, $.subscript_expression),
1249
1314
  aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1250
1315
  $._identifier,
1251
1316
  alias($._parenthesized_simple_target, $.parenthesized_expression)
@@ -1612,6 +1677,8 @@ module.exports = grammar({
1612
1677
  choice(
1613
1678
  $.member_expression,
1614
1679
  $.subscript_expression,
1680
+ alias($._assignment_member, $.member_expression),
1681
+ alias($._assignment_subscript, $.subscript_expression),
1615
1682
  $._identifier,
1616
1683
  aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1617
1684
  alias($._parenthesized_simple_target, $.parenthesized_expression)
@@ -1714,21 +1781,6 @@ module.exports = grammar({
1714
1781
  },
1715
1782
  });
1716
1783
 
1717
- /**
1718
- * @param {GrammarSymbols<'_primary_atom' | 'subscript_expression' | 'member_expression' | 'call_expression' | 'new_expression' | '_argumentless_new_expression'>} $
1719
- * @param {{atom?: RuleOrLiteral, subscript?: RuleOrLiteral, member?: RuleOrLiteral, call?: RuleOrLiteral}} [forms]
1720
- */
1721
- function leftHandSideExpression($, forms = {}) {
1722
- return choice(
1723
- forms.atom ?? $._primary_atom,
1724
- forms.subscript ?? $.subscript_expression,
1725
- forms.member ?? $.member_expression,
1726
- forms.call ?? $.call_expression,
1727
- $.new_expression,
1728
- alias($._argumentless_new_expression, $.new_expression)
1729
- );
1730
- }
1731
-
1732
1784
  /**
1733
1785
  * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'_escaped_let'>} $
1734
1786
  * @param {boolean} heritage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "22.0.0",
3
+ "version": "22.0.1",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -34,7 +34,7 @@
34
34
  }
35
35
  ],
36
36
  "metadata": {
37
- "version": "22.0.0",
37
+ "version": "22.0.1",
38
38
  "license": "MIT",
39
39
  "description": "JavaScript grammar for tree-sitter",
40
40
  "authors": [