@willbooster/tree-sitter-javascript 6.0.2 → 7.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
@@ -19,8 +19,8 @@ This fork fixes parsing bugs and raises conformance with [ECMAScript (ECMA-262)]
19
19
 
20
20
  The npm package ships `tree-sitter-javascript.wasm` for
21
21
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
22
- browsers, and Cloudflare Workers. The parser carries the ABI number of WillBooster/tree-sitter (`0x57420001`), so it
23
- loads only with that runtime, version 2.0.0 or newer; the upstream runtime rejects it. In Node.js and Bun, load it from
22
+ browsers, and Cloudflare Workers. The parser carries the ABI number of WillBooster/tree-sitter (`0x57420006`), so it
23
+ loads only with that runtime, version 7.0.5 or newer within major 7; the upstream runtime rejects it. In Node.js and Bun, load it from
24
24
  the package:
25
25
 
26
26
  ```js
@@ -64,12 +64,12 @@ The package also ships the node types in `src/node-types.json`, the highlight, i
64
64
  `require('@willbooster/tree-sitter-javascript/grammar')`). The crate ships `tree-sitter.json` and `queries/` too.
65
65
 
66
66
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-javascript) and the
67
- [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime, 2.0.0 or newer:
67
+ [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime, 7.0.5 or newer within major 7:
68
68
 
69
69
  ```toml
70
70
  [dependencies]
71
- tree-sitter = { package = "willbooster-tree-sitter", version = "2" }
72
- tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "5" }
71
+ tree-sitter = { package = "willbooster-tree-sitter", version = "7.0.5" }
72
+ tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "7" }
73
73
  ```
74
74
 
75
75
  ```rust
package/grammar.js CHANGED
@@ -118,6 +118,12 @@ module.exports = grammar({
118
118
  sym('_function_context_end'),
119
119
  sym('_arrow_context_end'),
120
120
  sym('_await_identifier'),
121
+ sym('_generator_function_start'),
122
+ sym('_async_generator_function_start'),
123
+ sym('_yield_keyword'),
124
+ sym('_yield_identifier'),
125
+ sym('_function_signature_start'),
126
+ sym('_async_function_signature_start'),
121
127
  ],
122
128
 
123
129
  extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -646,7 +652,10 @@ module.exports = grammar({
646
652
 
647
653
  yield_expression: ($) =>
648
654
  prec.right(
649
- seq('yield', choice(seq('*', $.expression), optional($.expression), sym('_line_break_ends_statement')))
655
+ seq(
656
+ alias(sym('_yield_keyword'), 'yield'),
657
+ choice(seq('*', $.expression), optional($.expression), sym('_line_break_ends_statement'))
658
+ )
650
659
  ),
651
660
 
652
661
  object: ($) =>
@@ -840,8 +849,7 @@ module.exports = grammar({
840
849
  ...(async ? ['async'] : []),
841
850
  'function',
842
851
  field('name', optional($.identifier)),
843
- $._call_signature,
844
- contextBody(async, field('body', $.statement_block))
852
+ functionScope(async, seq($._call_signature, field('body', $.statement_block)))
845
853
  )
846
854
  )
847
855
  ),
@@ -860,8 +868,7 @@ module.exports = grammar({
860
868
  ),
861
869
  seq(...(async ? ['async'] : []), 'function', field('name', $.identifier))
862
870
  ),
863
- $._call_signature,
864
- contextBody(async, field('body', $.statement_block))
871
+ functionScope(async, seq($._call_signature, field('body', $.statement_block)))
865
872
  )
866
873
  )
867
874
  ),
@@ -875,8 +882,7 @@ module.exports = grammar({
875
882
  'function',
876
883
  '*',
877
884
  field('name', optional($.identifier)),
878
- $._call_signature,
879
- contextBody(async, field('body', $.statement_block))
885
+ functionScope(async, seq($._call_signature, field('body', $.statement_block)), 'generator_function')
880
886
  )
881
887
  )
882
888
  ),
@@ -896,8 +902,7 @@ module.exports = grammar({
896
902
  ),
897
903
  seq(...(async ? ['async'] : []), 'function', '*', field('name', $.identifier))
898
904
  ),
899
- $._call_signature,
900
- contextBody(async, field('body', $.statement_block))
905
+ functionScope(async, seq($._call_signature, field('body', $.statement_block)), 'generator_function')
901
906
  )
902
907
  )
903
908
  ),
@@ -964,8 +969,7 @@ module.exports = grammar({
964
969
  ...(async ? ['async'] : []),
965
970
  'function',
966
971
  field('name', optional($.identifier)),
967
- $._call_signature,
968
- contextBody(async, field('body', $.statement_block))
972
+ functionScope(async, seq($._call_signature, field('body', $.statement_block)))
969
973
  )
970
974
  )
971
975
  ),
@@ -980,8 +984,7 @@ module.exports = grammar({
980
984
  'function',
981
985
  '*',
982
986
  field('name', optional($.identifier)),
983
- $._call_signature,
984
- contextBody(async, field('body', $.statement_block))
987
+ functionScope(async, seq($._call_signature, field('body', $.statement_block)), 'generator_function')
985
988
  )
986
989
  )
987
990
  ),
@@ -1487,14 +1490,22 @@ module.exports = grammar({
1487
1490
 
1488
1491
  method_definition: ($) =>
1489
1492
  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)))
1493
+ choice(
1494
+ ...[false, true].map((generator) =>
1495
+ seq(
1496
+ repeat(field('decorator', $.decorator)),
1497
+ optional('static'),
1498
+ ...(async ? ['async'] : []),
1499
+ ...(generator ? ['*'] : [optional(choice('get', 'set'))]),
1500
+ field('name', $._property_name),
1501
+ field('parameters', $.formal_parameters),
1502
+ functionScope(
1503
+ async,
1504
+ field('body', alias($._class_member_body, $.statement_block)),
1505
+ generator ? 'generator_function' : 'function'
1506
+ )
1507
+ )
1508
+ )
1498
1509
  )
1499
1510
  ),
1500
1511
 
@@ -1515,6 +1526,7 @@ module.exports = grammar({
1515
1526
  alias(
1516
1527
  choice(
1517
1528
  $.identifier,
1529
+ sym('_yield_identifier'),
1518
1530
  $._escaped_let,
1519
1531
  ...CONTEXTUAL_KEYWORDS.map((word) =>
1520
1532
  word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
@@ -1545,6 +1557,7 @@ module.exports = grammar({
1545
1557
 
1546
1558
  _reserved_identifier: ($) =>
1547
1559
  choice(
1560
+ sym('_yield_identifier'),
1548
1561
  ...MEMBER_MODIFIERS,
1549
1562
  $._escaped_let,
1550
1563
  ...CONTEXTUAL_KEYWORDS.map((word) =>
@@ -1590,8 +1603,10 @@ function functionContext(makeRule) {
1590
1603
  }
1591
1604
  /**
1592
1605
  * @param {boolean} async
1593
- * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} body
1606
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} content
1607
+ * @param {'function_signature' | 'generator_function' | 'function'} [kind]
1594
1608
  */
1595
- function contextBody(async, body) {
1596
- return seq(sym(async ? '_async_function_start' : '_sync_function_start'), body, sym('_function_context_end'));
1609
+ function functionScope(async, content, kind = 'function_signature') {
1610
+ const name = kind === 'function' && !async ? 'sync_function' : `${async ? 'async_' : ''}${kind}`;
1611
+ return seq(sym(`_${name}_start`), content, sym('_function_context_end'));
1597
1612
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "6.0.2",
3
+ "version": "7.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.27",
50
+ "@willbooster/web-tree-sitter": "7.0.5",
51
51
  "conventional-changelog-conventionalcommits": "10.4.1",
52
52
  "lefthook": "2.2.1",
53
53
  "oxfmt": "0.72.0",
@@ -61,7 +61,7 @@
61
61
  "wrangler": "4.149.0"
62
62
  },
63
63
  "peerDependencies": {
64
- "@willbooster/web-tree-sitter": "^2.0.0"
64
+ "@willbooster/web-tree-sitter": "^7.0.5"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@willbooster/web-tree-sitter": {
Binary file
package/tree-sitter.json CHANGED
@@ -20,11 +20,14 @@
20
20
  "injections": "queries/injections.scm",
21
21
  "locals": "queries/locals.scm",
22
22
  "tags": "queries/tags.scm",
23
- "injection-regex": "^(js|javascript)$"
23
+ "injection-regex": "^(js|javascript)$",
24
+ "external-files": [
25
+ "src/function_context.h"
26
+ ]
24
27
  }
25
28
  ],
26
29
  "metadata": {
27
- "version": "6.0.2",
30
+ "version": "7.0.1",
28
31
  "license": "MIT",
29
32
  "description": "JavaScript grammar for tree-sitter",
30
33
  "authors": [