@willbooster/tree-sitter-javascript 5.0.3 → 6.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.36.11-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.41.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-javascript.svg)](https://crates.io/crates/willbooster-tree-sitter-javascript)
10
10
 
11
11
  JavaScript and JSX grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
package/grammar.js CHANGED
@@ -113,6 +113,11 @@ module.exports = grammar({
113
113
  sym('_regex_flags_start'),
114
114
  sym('_argumentless_new_end'),
115
115
  sym('_constructor_async_function_start'),
116
+ sym('_sync_function_start'),
117
+ sym('_async_function_start'),
118
+ sym('_function_context_end'),
119
+ sym('_arrow_context_end'),
120
+ sym('_await_identifier'),
116
121
  ],
117
122
 
118
123
  extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -126,6 +131,7 @@ module.exports = grammar({
126
131
  supertypes: ($) => [
127
132
  $.statement,
128
133
  $.declaration,
134
+ $._decorated_export_declaration,
129
135
  $.expression,
130
136
  $.primary_expression,
131
137
  $.pattern,
@@ -223,6 +229,7 @@ module.exports = grammar({
223
229
 
224
230
  export_statement: ($) =>
225
231
  choice(
232
+ field('declaration', alias($._decorated_export_declaration, $.declaration)),
226
233
  seq(
227
234
  'export',
228
235
  choice(
@@ -236,7 +243,6 @@ module.exports = grammar({
236
243
  $._semicolon
237
244
  ),
238
245
  seq(
239
- repeat(field('decorator', $.decorator)),
240
246
  'export',
241
247
  choice(
242
248
  field('declaration', $.declaration),
@@ -246,6 +252,23 @@ module.exports = grammar({
246
252
  )
247
253
  ),
248
254
 
255
+ _decorated_export_declaration: ($) => alias($._decorated_export_class, $.class_declaration),
256
+
257
+ _decorated_export_class: ($) =>
258
+ prec(
259
+ 'declaration',
260
+ seq(
261
+ repeat1(field('decorator', $.decorator)),
262
+ 'export',
263
+ choice(
264
+ seq('class', field('name', $.identifier)),
265
+ seq('default', 'class', field('name', optional($.identifier)))
266
+ ),
267
+ optional($.class_heritage),
268
+ field('body', $.class_body)
269
+ )
270
+ ),
271
+
249
272
  namespace_export: ($) => seq('*', 'as', $._module_export_name),
250
273
 
251
274
  export_clause: ($) => seq('{', commaSep($.export_specifier), optional(','), '}'),
@@ -812,85 +835,97 @@ module.exports = grammar({
812
835
  function_expression: ($) =>
813
836
  prec(
814
837
  'literal',
815
- seq(
816
- optional('async'),
817
- 'function',
818
- field('name', optional($.identifier)),
819
- $._call_signature,
820
- field('body', $.statement_block)
838
+ functionContext((async) =>
839
+ seq(
840
+ ...(async ? ['async'] : []),
841
+ 'function',
842
+ field('name', optional($.identifier)),
843
+ $._call_signature,
844
+ contextBody(async, field('body', $.statement_block))
845
+ )
821
846
  )
822
847
  ),
823
848
 
824
849
  function_declaration: ($) =>
825
850
  prec.right(
826
851
  'declaration',
827
- seq(
828
- choice(
829
- seq(
830
- sym('_default_declaration_start'),
831
- optional('async'),
832
- 'function',
833
- field('name', optional($.identifier))
852
+ functionContext((async) =>
853
+ seq(
854
+ choice(
855
+ seq(
856
+ sym('_default_declaration_start'),
857
+ ...(async ? ['async'] : []),
858
+ 'function',
859
+ field('name', optional($.identifier))
860
+ ),
861
+ seq(...(async ? ['async'] : []), 'function', field('name', $.identifier))
834
862
  ),
835
- seq(optional('async'), 'function', field('name', $.identifier))
836
- ),
837
- $._call_signature,
838
- field('body', $.statement_block)
863
+ $._call_signature,
864
+ contextBody(async, field('body', $.statement_block))
865
+ )
839
866
  )
840
867
  ),
841
868
 
842
869
  generator_function: ($) =>
843
870
  prec(
844
871
  'literal',
845
- seq(
846
- optional('async'),
847
- 'function',
848
- '*',
849
- field('name', optional($.identifier)),
850
- $._call_signature,
851
- field('body', $.statement_block)
872
+ functionContext((async) =>
873
+ seq(
874
+ ...(async ? ['async'] : []),
875
+ 'function',
876
+ '*',
877
+ field('name', optional($.identifier)),
878
+ $._call_signature,
879
+ contextBody(async, field('body', $.statement_block))
880
+ )
852
881
  )
853
882
  ),
854
883
 
855
884
  generator_function_declaration: ($) =>
856
885
  prec.right(
857
886
  'declaration',
858
- seq(
859
- choice(
860
- seq(
861
- sym('_default_declaration_start'),
862
- optional('async'),
863
- 'function',
864
- '*',
865
- field('name', optional($.identifier))
887
+ functionContext((async) =>
888
+ seq(
889
+ choice(
890
+ seq(
891
+ sym('_default_declaration_start'),
892
+ ...(async ? ['async'] : []),
893
+ 'function',
894
+ '*',
895
+ field('name', optional($.identifier))
896
+ ),
897
+ seq(...(async ? ['async'] : []), 'function', '*', field('name', $.identifier))
866
898
  ),
867
- seq(optional('async'), 'function', '*', field('name', $.identifier))
868
- ),
869
- $._call_signature,
870
- field('body', $.statement_block)
899
+ $._call_signature,
900
+ contextBody(async, field('body', $.statement_block))
901
+ )
871
902
  )
872
903
  ),
873
904
 
874
905
  arrow_function: ($) =>
875
906
  prec.right(
876
- seq(
877
- optional('async'),
878
- choice(
879
- field(
880
- 'parameter',
881
- choice(alias($._reserved_identifier, $.identifier), alias($.undefined, $.identifier), $.identifier)
907
+ functionContext((async) =>
908
+ seq(
909
+ ...(async ? ['async'] : []),
910
+ choice(
911
+ field(
912
+ 'parameter',
913
+ choice(alias($._reserved_identifier, $.identifier), alias($.undefined, $.identifier), $.identifier)
914
+ ),
915
+ $._call_signature
882
916
  ),
883
- $._call_signature
884
- ),
885
- '=>',
886
- choice(
887
- field('body', $.expression),
888
- seq(
889
- field('body', $.statement_block),
890
- optional(seq(sym('_arrow_function_block_end'), optional(sym('_arrow_function_block_continuation'))))
891
- )
892
- ),
893
- optional(sym('_completed_arrow_function'))
917
+ '=>',
918
+ sym(async ? '_async_function_start' : '_sync_function_start'),
919
+ choice(
920
+ seq(field('body', $.expression), sym('_arrow_context_end')),
921
+ seq(
922
+ field('body', $.statement_block),
923
+ optional(seq(sym('_arrow_function_block_end'), optional(sym('_arrow_function_block_continuation')))),
924
+ sym('_function_context_end')
925
+ )
926
+ ),
927
+ optional(sym('_completed_arrow_function'))
928
+ )
894
929
  )
895
930
  ),
896
931
 
@@ -923,27 +958,31 @@ module.exports = grammar({
923
958
  _constructor_function_expression: ($) =>
924
959
  prec(
925
960
  'literal',
926
- seq(
927
- optional(sym('_constructor_async_function_start')),
928
- optional('async'),
929
- 'function',
930
- field('name', optional($.identifier)),
931
- $._call_signature,
932
- field('body', $.statement_block)
961
+ functionContext((async) =>
962
+ seq(
963
+ optional(sym('_constructor_async_function_start')),
964
+ ...(async ? ['async'] : []),
965
+ 'function',
966
+ field('name', optional($.identifier)),
967
+ $._call_signature,
968
+ contextBody(async, field('body', $.statement_block))
969
+ )
933
970
  )
934
971
  ),
935
972
 
936
973
  _constructor_generator_function: ($) =>
937
974
  prec(
938
975
  'literal',
939
- seq(
940
- optional(sym('_constructor_async_function_start')),
941
- optional('async'),
942
- 'function',
943
- '*',
944
- field('name', optional($.identifier)),
945
- $._call_signature,
946
- field('body', $.statement_block)
976
+ functionContext((async) =>
977
+ seq(
978
+ optional(sym('_constructor_async_function_start')),
979
+ ...(async ? ['async'] : []),
980
+ 'function',
981
+ '*',
982
+ field('name', optional($.identifier)),
983
+ $._call_signature,
984
+ contextBody(async, field('body', $.statement_block))
985
+ )
947
986
  )
948
987
  ),
949
988
 
@@ -1447,14 +1486,16 @@ module.exports = grammar({
1447
1486
  rest_pattern: ($) => prec.right(seq('...', choice($._lhs_expression, $.parenthesized_expression))),
1448
1487
 
1449
1488
  method_definition: ($) =>
1450
- seq(
1451
- repeat(field('decorator', $.decorator)),
1452
- optional('static'),
1453
- optional('async'),
1454
- optional(choice('get', 'set', '*')),
1455
- field('name', $._property_name),
1456
- field('parameters', $.formal_parameters),
1457
- field('body', alias($._class_member_body, $.statement_block))
1489
+ functionContext((async) =>
1490
+ seq(
1491
+ repeat(field('decorator', $.decorator)),
1492
+ optional('static'),
1493
+ ...(async ? ['async'] : []),
1494
+ optional(choice('get', 'set', '*')),
1495
+ field('name', $._property_name),
1496
+ field('parameters', $.formal_parameters),
1497
+ contextBody(async, field('body', alias($._class_member_body, $.statement_block)))
1498
+ )
1458
1499
  ),
1459
1500
 
1460
1501
  // The body of a method or a static block, a rule of its own rather than statement_block: sharing it let tree-sitter
@@ -1475,7 +1516,9 @@ module.exports = grammar({
1475
1516
  choice(
1476
1517
  $.identifier,
1477
1518
  $._escaped_let,
1478
- ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? sym('_await_keyword') : word))
1519
+ ...CONTEXTUAL_KEYWORDS.map((word) =>
1520
+ word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
1521
+ )
1479
1522
  ),
1480
1523
  sym('property_identifier')
1481
1524
  ),
@@ -1504,7 +1547,9 @@ module.exports = grammar({
1504
1547
  choice(
1505
1548
  ...MEMBER_MODIFIERS,
1506
1549
  $._escaped_let,
1507
- ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? sym('_await_keyword') : word))
1550
+ ...CONTEXTUAL_KEYWORDS.map((word) =>
1551
+ word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
1552
+ )
1508
1553
  ),
1509
1554
 
1510
1555
  _semicolon: () =>
@@ -1538,3 +1583,15 @@ function commaSep1(rule) {
1538
1583
  function commaSep(rule) {
1539
1584
  return optional(commaSep1(rule));
1540
1585
  }
1586
+
1587
+ /** @param {(isAsync: boolean) => import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} makeRule */
1588
+ function functionContext(makeRule) {
1589
+ return choice(makeRule(false), makeRule(true));
1590
+ }
1591
+ /**
1592
+ * @param {boolean} async
1593
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} body
1594
+ */
1595
+ function contextBody(async, body) {
1596
+ return seq(sym(async ? '_async_function_start' : '_sync_function_start'), body, sym('_function_context_end'));
1597
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "5.0.3",
3
+ "version": "6.0.1",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -47,7 +47,7 @@
47
47
  "@willbooster/oxfmt-config": "1.2.2",
48
48
  "@willbooster/oxlint-config": "1.4.8",
49
49
  "@willbooster/wb": "22.26.1",
50
- "@willbooster/web-tree-sitter": "2.0.24",
50
+ "@willbooster/web-tree-sitter": "2.0.27",
51
51
  "conventional-changelog-conventionalcommits": "10.4.1",
52
52
  "lefthook": "2.2.1",
53
53
  "oxfmt": "0.72.0",
@@ -56,7 +56,6 @@
56
56
  "playwright": "1.64.0",
57
57
  "semantic-release": "25.0.9",
58
58
  "sort-package-json": "4.0.0",
59
- "typescript": "7.0.2",
60
59
  "vite": "8.3.4",
61
60
  "vitest": "5.0.3",
62
61
  "wrangler": "4.149.0"
@@ -1146,16 +1146,6 @@
1146
1146
  }
1147
1147
  ]
1148
1148
  },
1149
- "decorator": {
1150
- "multiple": true,
1151
- "required": false,
1152
- "types": [
1153
- {
1154
- "type": "decorator",
1155
- "named": true
1156
- }
1157
- ]
1158
- },
1159
1149
  "source": {
1160
1150
  "multiple": false,
1161
1151
  "required": false,
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "5.0.3",
27
+ "version": "6.0.1",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [