@willbooster/tree-sitter-javascript 16.0.0 → 18.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/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.48.9-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.51.1-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
@@ -15,17 +15,24 @@ to its authors and contributors. This is not an official release of that project
15
15
  This fork fixes parsing bugs and raises conformance with [ECMAScript (ECMA-262)](https://tc39.es/ecma262/) and
16
16
  [JSX](https://facebook.github.io/jsx/).
17
17
 
18
+ ## Support Scope
19
+
20
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
21
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
22
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
23
+ the trees that error recovery produces may change; such changes are released as new major versions.
24
+
18
25
  ## Usage
19
26
 
20
27
  The npm package ships two languages for
21
28
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
22
29
  browsers, and Cloudflare Workers. The parser carries the ABI number of WillBooster/tree-sitter (`0x5742000b`), so it
23
- requires that runtime ABI; the upstream runtime rejects it. This package is tested with runtime 15.0.0, and its optional peer dependency covers major 15. In Node.js and Bun, load it from
30
+ requires that runtime ABI; the upstream runtime rejects it. This package is tested with runtime 15.5.4, and its optional peer dependency covers major 15. In Node.js and Bun, load it from
24
31
  the package. Choose `tree-sitter-javascript.wasm` for the Module goal, or
25
32
  `tree-sitter-javascript_script.wasm` for the Script goal. The source goal comes from the host or file type;
26
33
  `.mjs` uses Module and `.cjs` uses Script, while `.js` depends on the host. For example, `await\nvalue` is one
27
34
  await expression in a Module and two identifier statements in a Script. Both languages preserve the same node
28
- schema and query names. As with other tree-sitter grammars, parsing does not enforce every ECMAScript early error.
35
+ schema. As with other tree-sitter grammars, parsing does not enforce every ECMAScript early error.
29
36
  For the native CLI, select Script with `tree-sitter parse --grammar-path grammars/script`.
30
37
 
31
38
  ```js
@@ -68,17 +75,16 @@ const parser = new Parser();
68
75
  parser.setLanguage(await Language.load(javascript));
69
76
  ```
70
77
 
71
- The package also ships the node types in `src/node-types.json`, the highlight, injection, locals, and tags queries in
72
- `queries/` that `tree-sitter.json` lists, and `grammar.js` for grammars that extend this one (e.g.
73
- `require('@willbooster/tree-sitter-javascript/grammar')`). Its JSDoc describes the array/formal and object-rest
74
- extension hooks. The crate ships `tree-sitter.json` and `queries/` too.
78
+ The package also ships the node types in `src/node-types.json`, `tree-sitter.json`, and `grammar.js` for grammars
79
+ that extend this one (e.g. `require('@willbooster/tree-sitter-javascript/grammar')`). Its JSDoc describes the
80
+ array/formal and object-rest extension hooks. The crate ships `tree-sitter.json` too.
75
81
 
76
82
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-javascript) and the
77
- [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime with the matching ABI. The tested version is 15.0.0:
83
+ [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime with the matching ABI. The tested version is 15.5.4:
78
84
 
79
85
  ```toml
80
86
  [dependencies]
81
- tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
87
+ tree-sitter = { package = "willbooster-tree-sitter", version = "15.5.4" }
82
88
  tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "16" }
83
89
  ```
84
90
 
@@ -114,9 +120,6 @@ and the release build regenerate the parsers before compiling them.
114
120
  `bun run test` runs:
115
121
 
116
122
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
117
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
118
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
119
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
120
123
  - a check that the real-world JavaScript files in `examples/`, the checked-in ones and those of the cloned repository,
121
124
  fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repository. The example
122
125
  repository is pinned to a commit in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -129,13 +132,10 @@ and the release build regenerate the parsers before compiling them.
129
132
  Node.js compatibility (`test/unit/workers.test.ts`). Run `bun run test/ci-setup` once before the first
130
133
  run to install Chromium and, on Linux, the system libraries it needs;
131
134
  - a check that `package.json` and `Cargo.lock` lock the same WillBooster/tree-sitter runtime version
132
- (`test/unit/runtimeVersion.test.ts`);
133
- - a check that the queries `tree-sitter.json` lists compile against the Wasm build and are in both the npm package and
134
- the crate (`test/unit/queries.test.ts`).
135
+ (`test/unit/runtimeVersion.test.ts`).
135
136
 
136
137
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` instead of the CLI's cache shared
137
- by every checkout, and `mise.toml` sets `TREE_SITTER_LIBDIR` to it for any other command run in the checkout;
138
- `script/fuzz-corpus` builds a parser of its own in `.tmp/fuzz` for each run and deletes it afterwards.
138
+ by every checkout, and `mise.toml` sets `TREE_SITTER_LIBDIR` to it for any other command run in the checkout.
139
139
 
140
140
  CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
141
141
  parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  // @ts-check
9
9
 
10
+ /** @import {GrammarSymbols, RuleOrLiteral} from '@willbooster/web-tree-sitter/dsl' */
11
+
10
12
  // The CLI injects the DSL before loading this CommonJS grammar.
11
13
  const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token, reserved } =
12
14
  /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
@@ -51,7 +53,6 @@ const RESERVED_WORDS = [
51
53
  ];
52
54
  const NAMED_RESERVED_WORDS = new Set(['this', 'super', 'true', 'false', 'null']);
53
55
 
54
- // Words that are keywords only in some positions and identifiers elsewhere.
55
56
  const MEMBER_MODIFIERS = ['get', 'set', 'static'];
56
57
  const CONTEXTUAL_KEYWORDS = ['async', 'await', 'let', 'of', 'using'];
57
58
  const CLASSIC_ASSIGNMENT_OPERATORS = ['+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=', '>>=', '>>>=', '<<=', '**='];
@@ -77,7 +78,8 @@ module.exports = grammar({
77
78
  // _arrow_function_block_continuation, since the arrow function may be, e.g., an argument.
78
79
  sym('_arrow_function_block_end'),
79
80
  sym('_arrow_function_block_continuation'),
80
- // Bindings emit a boundary to preserve reuse; the other flags only select a scanner line-break rule.
81
+ // Bindings emit a boundary where the scanner decides from what follows whether a line break ends the declaration;
82
+ // the other flags only select a scanner line-break rule.
81
83
  // Keep those flags alternatives to what follows: leading optional flags duplicate parse states.
82
84
  sym('_line_break_ends_statement'),
83
85
  sym('_line_break_after_binding'),
@@ -100,7 +102,8 @@ module.exports = grammar({
100
102
  // Emitted zero-width decision preserves direct operands and identifier statements before yield.
101
103
  sym('_await_yield_identifier_start'),
102
104
  sym('_await_yield_identifier_context'),
103
- // Emitted zero-width after a postfix update; carries the pending statement boundary across reuse.
105
+ // Emitted zero-width after a postfix update; records whether a line break before `(`, `[`, or a template ends the
106
+ // statement, for the automatic semicolon that follows.
104
107
  sym('_postfix_update_end'),
105
108
  sym('_await_keyword'),
106
109
  sym('_let'),
@@ -128,6 +131,9 @@ module.exports = grammar({
128
131
  sym('_call_arguments_context'),
129
132
  sym('_async_keyword'),
130
133
  sym('_line_break_before_from'),
134
+ sym('_class_heritage_end'),
135
+ sym('_class_heritage_yield_identifier'),
136
+ sym('_class_heritage_await_identifier'),
131
137
  ],
132
138
 
133
139
  extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -146,6 +152,8 @@ module.exports = grammar({
146
152
  $._binary_operand,
147
153
  $._unary_operand,
148
154
  $.primary_expression,
155
+ $._class_heritage_expression,
156
+ $._class_heritage_primary,
149
157
  $.pattern,
150
158
  $._non_rest_pattern,
151
159
  $._rest_pattern,
@@ -167,6 +175,7 @@ module.exports = grammar({
167
175
  $._semicolon,
168
176
  $._identifier,
169
177
  $._reserved_identifier,
178
+ $._expression_identifier,
170
179
  $._jsx_attribute,
171
180
  $._jsx_element_name,
172
181
  $._jsx_child,
@@ -220,6 +229,7 @@ module.exports = grammar({
220
229
  [$._simple_target_primary, $._non_rest_pattern],
221
230
  [$._primary_atom, $._simple_target_primary, $._non_rest_pattern],
222
231
  [$._call_callee, $.call_expression],
232
+ [$._class_heritage_expression, $._class_heritage_call],
223
233
  [$.for_in_clause, $._primary_atom],
224
234
  [$._primary_atom, $.rest_pattern],
225
235
  [$._primary_atom, $._object_rest_pattern],
@@ -249,10 +259,6 @@ module.exports = grammar({
249
259
 
250
260
  hash_bang_line: () => /#![^\n\r\u2028\u2029]*/,
251
261
 
252
- //
253
- // Export declarations
254
- //
255
-
256
262
  export_statement: ($) =>
257
263
  choice(
258
264
  field('declaration', alias($._decorated_export_declaration, $.declaration)),
@@ -327,10 +333,6 @@ module.exports = grammar({
327
333
  $.using_declaration
328
334
  ),
329
335
 
330
- //
331
- // Import declarations
332
- //
333
-
334
336
  import: () => token('import'),
335
337
 
336
338
  import_statement: ($) =>
@@ -363,10 +365,6 @@ module.exports = grammar({
363
365
 
364
366
  import_attribute: ($) => seq('with', $.object),
365
367
 
366
- //
367
- // Statements
368
- //
369
-
370
368
  statement: ($) =>
371
369
  choice(
372
370
  $.export_statement,
@@ -486,8 +484,7 @@ module.exports = grammar({
486
484
  _for_condition: ($) => field('condition', choice(seq($._expressions, ';'), $.empty_statement)),
487
485
 
488
486
  // ECMAScript inserts no semicolon inside a for header, so these declarations end only with `;`. Accepting an
489
- // automatic semicolon there made `for (let x\n of y)` ambiguous until `of`, and an incremental reparse could
490
- // reuse a declaration built when that ambiguity was resolved differently.
487
+ // automatic semicolon there would make `for (let x\n of y)` ambiguous until `of`.
491
488
  for_lexical_declaration: ($) =>
492
489
  seq(
493
490
  field('kind', choice('let', 'const')),
@@ -620,10 +617,6 @@ module.exports = grammar({
620
617
  field('body', $._single_statement)
621
618
  ),
622
619
 
623
- //
624
- // Statement components
625
- //
626
-
627
620
  switch_body: ($) => seq('{', repeat(choice($.switch_case, $.switch_default)), '}'),
628
621
 
629
622
  switch_case: ($) => seq('case', field('value', $._expressions), ':', field('body', repeat($._statement))),
@@ -641,9 +634,6 @@ module.exports = grammar({
641
634
 
642
635
  parenthesized_expression: ($) => seq('(', $._expressions, ')'),
643
636
 
644
- //
645
- // Expressions
646
- //
647
637
  _expressions: ($) => choice($.expression, $.sequence_expression),
648
638
 
649
639
  expression: ($) =>
@@ -664,16 +654,7 @@ module.exports = grammar({
664
654
 
665
655
  _unary_operand: ($) => choice($.primary_expression, $.await_expression, $.unary_expression, $.update_expression),
666
656
 
667
- primary_expression: ($) =>
668
- choice(
669
- $._primary_atom,
670
- $.subscript_expression,
671
- $.member_expression,
672
- $.call_expression,
673
- $.new_expression,
674
- alias($._argumentless_new_expression, $.new_expression),
675
- $.arrow_function
676
- ),
657
+ primary_expression: ($) => choice(leftHandSideExpression($), $.arrow_function),
677
658
 
678
659
  yield_expression: ($) =>
679
660
  prec.right(
@@ -759,9 +740,6 @@ module.exports = grammar({
759
740
  jsx_element: ($) =>
760
741
  seq(field('open_tag', $.jsx_opening_element), repeat($._jsx_child), field('close_tag', $.jsx_closing_element)),
761
742
 
762
- // An entity can be named, numeric (decimal), or numeric (hexadecimal). The
763
- // longest entity name is 29 characters long, and the HTML spec says that
764
- // no more will ever be added.
765
743
  html_character_reference: () => /&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});/,
766
744
 
767
745
  jsx_expression: ($) => seq('{', optional(choice($.expression, $.sequence_expression, $.spread_element)), '}'),
@@ -833,13 +811,8 @@ module.exports = grammar({
833
811
  )
834
812
  ),
835
813
 
836
- // Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
837
- // We give names to the token() constructs containing a regexp
838
- // so as to obtain a node in the CST.
839
- //
840
814
  unescaped_double_jsx_string_fragment: () => token.immediate(prec(1, /([^"&]|&[^#A-Za-z"&])+/)),
841
815
 
842
- // same here
843
816
  unescaped_single_jsx_string_fragment: () => token.immediate(prec(1, /([^'&]|&[^#A-Za-z'&])+/)),
844
817
 
845
818
  // An `&` that does not start a complete html_character_reference is a literal character, as in HTML. The lexer
@@ -878,7 +851,31 @@ module.exports = grammar({
878
851
  )
879
852
  ),
880
853
 
881
- class_heritage: ($) => seq('extends', $.expression),
854
+ class_heritage: ($) =>
855
+ seq('extends', alias($._class_heritage_expression, $.expression), sym('_class_heritage_end')),
856
+
857
+ _class_heritage_expression: ($) => alias($._class_heritage_primary, $.primary_expression),
858
+
859
+ _class_heritage_primary: ($) =>
860
+ leftHandSideExpression($, {
861
+ atom: $._class_heritage_atom,
862
+ call: alias($._class_heritage_call, $.call_expression),
863
+ member: alias($._class_heritage_member, $.member_expression),
864
+ subscript: alias($._class_heritage_subscript, $.subscript_expression),
865
+ }),
866
+
867
+ _class_heritage_atom: ($) => primaryAtom($, $._expression_identifier),
868
+
869
+ _class_heritage_call: ($) =>
870
+ callExpression(
871
+ $,
872
+ alias($._class_heritage_expression, $.expression),
873
+ alias($._class_heritage_primary, $.primary_expression)
874
+ ),
875
+
876
+ _class_heritage_member: ($) => memberExpression($, alias($._class_heritage_expression, $.expression)),
877
+
878
+ _class_heritage_subscript: ($) => subscriptExpression($, alias($._class_heritage_expression, $.expression)),
882
879
 
883
880
  function_expression: ($) =>
884
881
  prec(
@@ -991,46 +988,9 @@ module.exports = grammar({
991
988
 
992
989
  optional_chain: () => '?.',
993
990
 
994
- call_expression: ($) =>
995
- choice(
996
- prec(
997
- 'call',
998
- seq(field('function', choice(alias($._call_callee, $.expression), $.import)), field('arguments', $.arguments))
999
- ),
1000
- prec('template_call', seq(field('function', $.primary_expression), field('arguments', $.template_string))),
1001
- prec(
1002
- 'member',
1003
- seq(
1004
- field('function', $.primary_expression),
1005
- field('optional_chain', $.optional_chain),
1006
- field('arguments', $.arguments)
1007
- )
1008
- )
1009
- ),
991
+ call_expression: ($) => callExpression($, alias($._call_callee, $.expression), $.primary_expression),
1010
992
 
1011
- _primary_atom: ($) =>
1012
- choice(
1013
- $._jsx_element,
1014
- $.parenthesized_expression,
1015
- $._identifier,
1016
- alias(sym('_await_yield_identifier'), $.identifier),
1017
- aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1018
- $.this,
1019
- $.super,
1020
- $.number,
1021
- $.string,
1022
- $.template_string,
1023
- $.regex,
1024
- $.true,
1025
- $.false,
1026
- $.null,
1027
- $.object,
1028
- $.array,
1029
- $.function_expression,
1030
- $.generator_function,
1031
- $.class,
1032
- $.meta_property
1033
- ),
993
+ _primary_atom: ($) => primaryAtom($, $._reserved_identifier),
1034
994
 
1035
995
  _assignment_call: ($) =>
1036
996
  prec(
@@ -1220,33 +1180,9 @@ module.exports = grammar({
1220
1180
  )
1221
1181
  ),
1222
1182
 
1223
- member_expression: ($) =>
1224
- prec(
1225
- 'member',
1226
- seq(
1227
- field('object', choice(alias($._call_callee, $.expression), $.import)),
1228
- choice('.', field('optional_chain', $.optional_chain)),
1229
- field(
1230
- 'property',
1231
- choice(
1232
- $.private_property_identifier,
1233
- reserved('properties', alias($.identifier, sym('property_identifier')))
1234
- )
1235
- )
1236
- )
1237
- ),
1183
+ member_expression: ($) => memberExpression($, alias($._call_callee, $.expression)),
1238
1184
 
1239
- subscript_expression: ($) =>
1240
- prec.right(
1241
- 'member',
1242
- seq(
1243
- field('object', alias($._call_callee, $.expression)),
1244
- optional(field('optional_chain', $.optional_chain)),
1245
- '[',
1246
- field('index', $._expressions),
1247
- ']'
1248
- )
1249
- ),
1185
+ subscript_expression: ($) => subscriptExpression($, alias($._call_callee, $.expression)),
1250
1186
 
1251
1187
  _lhs_expression: ($) =>
1252
1188
  choice(
@@ -1411,10 +1347,6 @@ module.exports = grammar({
1411
1347
 
1412
1348
  sequence_expression: ($) => prec.right(commaSep1($.expression)),
1413
1349
 
1414
- //
1415
- // Primitives
1416
- //
1417
-
1418
1350
  string: ($) =>
1419
1351
  choice(
1420
1352
  seq(
@@ -1429,13 +1361,8 @@ module.exports = grammar({
1429
1361
  )
1430
1362
  ),
1431
1363
 
1432
- // Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
1433
- // We give names to the token() constructs containing a regexp
1434
- // so as to obtain a node in the CST.
1435
- //
1436
1364
  unescaped_double_string_fragment: () => token.immediate(prec(1, /[^"\\\r\n]+/)),
1437
1365
 
1438
- // same here
1439
1366
  unescaped_single_string_fragment: () => token.immediate(prec(1, /[^'\\\r\n]+/)),
1440
1367
 
1441
1368
  escape_sequence: () =>
@@ -1483,19 +1410,10 @@ module.exports = grammar({
1483
1410
  -1,
1484
1411
  repeat1(
1485
1412
  choice(
1486
- seq(
1487
- '[',
1488
- repeat(
1489
- choice(
1490
- seq('\\', /[^\n\r\u2028\u2029]/), // escaped character
1491
- /[^\]\\\n\r\u2028\u2029]/ // any character besides ']', '\', or a line terminator
1492
- )
1493
- ),
1494
- ']'
1495
- ), // square-bracket-delimited character class
1496
- seq('\\', /[^\n\r\u2028\u2029]/), // escaped character
1413
+ seq('[', repeat(choice(seq('\\', /[^\n\r\u2028\u2029]/), /[^\]\\\n\r\u2028\u2029]/)), ']'),
1414
+ seq('\\', /[^\n\r\u2028\u2029]/),
1497
1415
  // oxlint-disable-next-line no-useless-escape -- tree-sitter's regex parser rejects an unescaped `[` in a character class.
1498
- /[^/\\\[\n\r\u2028\u2029]/ // any character besides '[', '\', '/', or a line terminator
1416
+ /[^/\\\[\n\r\u2028\u2029]/
1499
1417
  )
1500
1418
  )
1501
1419
  )
@@ -1569,10 +1487,6 @@ module.exports = grammar({
1569
1487
  null: () => 'null',
1570
1488
  undefined: () => 'undefined',
1571
1489
 
1572
- //
1573
- // Expression components
1574
- //
1575
-
1576
1490
  arguments: ($) =>
1577
1491
  seq(choice('(', sym('_call_arguments_context')), commaSep(optional(choice($.expression, $.spread_element))), ')'),
1578
1492
 
@@ -1793,15 +1707,9 @@ module.exports = grammar({
1793
1707
 
1794
1708
  computed_property_name: ($) => seq('[', $.expression, ']'),
1795
1709
 
1796
- _reserved_identifier: ($) =>
1797
- choice(
1798
- sym('_yield_identifier'),
1799
- ...MEMBER_MODIFIERS,
1800
- $._escaped_let,
1801
- ...CONTEXTUAL_KEYWORDS.map((word) =>
1802
- word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
1803
- )
1804
- ),
1710
+ _reserved_identifier: ($) => contextualIdentifier($, false),
1711
+
1712
+ _expression_identifier: ($) => contextualIdentifier($, true),
1805
1713
 
1806
1714
  _semicolon: () =>
1807
1715
  choice(
@@ -1813,6 +1721,118 @@ module.exports = grammar({
1813
1721
  },
1814
1722
  });
1815
1723
 
1724
+ /**
1725
+ * @param {GrammarSymbols<'_primary_atom' | 'subscript_expression' | 'member_expression' | 'call_expression' | 'new_expression' | '_argumentless_new_expression'>} $
1726
+ * @param {{atom?: RuleOrLiteral, subscript?: RuleOrLiteral, member?: RuleOrLiteral, call?: RuleOrLiteral}} [forms]
1727
+ */
1728
+ function leftHandSideExpression($, forms = {}) {
1729
+ return choice(
1730
+ forms.atom ?? $._primary_atom,
1731
+ forms.subscript ?? $.subscript_expression,
1732
+ forms.member ?? $.member_expression,
1733
+ forms.call ?? $.call_expression,
1734
+ $.new_expression,
1735
+ alias($._argumentless_new_expression, $.new_expression)
1736
+ );
1737
+ }
1738
+
1739
+ /**
1740
+ * @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'_escaped_let'>} $
1741
+ * @param {boolean} heritage
1742
+ */
1743
+ function contextualIdentifier($, heritage) {
1744
+ const yieldWord = heritage ? sym('_class_heritage_yield_identifier') : sym('_yield_identifier');
1745
+ const awaitWord = heritage
1746
+ ? sym('_class_heritage_await_identifier')
1747
+ : choice(sym('_await_keyword'), sym('_await_identifier'));
1748
+ return choice(
1749
+ yieldWord,
1750
+ ...MEMBER_MODIFIERS,
1751
+ $._escaped_let,
1752
+ ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? awaitWord : word))
1753
+ );
1754
+ }
1755
+
1756
+ /**
1757
+ * @param {GrammarSymbols<'import' | 'arguments' | 'template_string' | 'optional_chain'>} $
1758
+ * @param {RuleOrLiteral} callee
1759
+ * @param {RuleOrLiteral} primary
1760
+ */
1761
+ function callExpression($, callee, primary) {
1762
+ return choice(
1763
+ prec('call', seq(field('function', choice(callee, $.import)), field('arguments', $.arguments))),
1764
+ prec('template_call', seq(field('function', primary), field('arguments', $.template_string))),
1765
+ prec(
1766
+ 'member',
1767
+ seq(field('function', primary), field('optional_chain', $.optional_chain), field('arguments', $.arguments))
1768
+ )
1769
+ );
1770
+ }
1771
+
1772
+ /**
1773
+ * @param {GrammarSymbols<'_jsx_element' | 'parenthesized_expression' | '_identifier' | 'identifier' | 'this' | 'super' | 'number' | 'string' | 'template_string' | 'regex' | 'true' | 'false' | 'null' | 'object' | 'array' | 'function_expression' | 'generator_function' | 'class' | 'meta_property'>} $
1774
+ * @param {RuleOrLiteral} identifier
1775
+ */
1776
+ function primaryAtom($, identifier) {
1777
+ return choice(
1778
+ $._jsx_element,
1779
+ $.parenthesized_expression,
1780
+ $._identifier,
1781
+ alias(sym('_await_yield_identifier'), $.identifier),
1782
+ aliasWithAsyncKeyword(identifier, $.identifier),
1783
+ $.this,
1784
+ $.super,
1785
+ $.number,
1786
+ $.string,
1787
+ $.template_string,
1788
+ $.regex,
1789
+ $.true,
1790
+ $.false,
1791
+ $.null,
1792
+ $.object,
1793
+ $.array,
1794
+ $.function_expression,
1795
+ $.generator_function,
1796
+ $.class,
1797
+ $.meta_property
1798
+ );
1799
+ }
1800
+
1801
+ /**
1802
+ * @param {GrammarSymbols<'import' | 'optional_chain' | 'private_property_identifier' | 'identifier'>} $
1803
+ * @param {RuleOrLiteral} object
1804
+ */
1805
+ function memberExpression($, object) {
1806
+ return prec(
1807
+ 'member',
1808
+ seq(
1809
+ field('object', choice(object, $.import)),
1810
+ choice('.', field('optional_chain', $.optional_chain)),
1811
+ field(
1812
+ 'property',
1813
+ choice($.private_property_identifier, reserved('properties', alias($.identifier, sym('property_identifier'))))
1814
+ )
1815
+ )
1816
+ );
1817
+ }
1818
+
1819
+ /**
1820
+ * @param {GrammarSymbols<'optional_chain' | '_expressions'>} $
1821
+ * @param {RuleOrLiteral} object
1822
+ */
1823
+ function subscriptExpression($, object) {
1824
+ return prec.right(
1825
+ 'member',
1826
+ seq(
1827
+ field('object', object),
1828
+ optional(field('optional_chain', $.optional_chain)),
1829
+ '[',
1830
+ field('index', $._expressions),
1831
+ ']'
1832
+ )
1833
+ );
1834
+ }
1835
+
1816
1836
  /**
1817
1837
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
1818
1838
  * @param {import('@willbooster/web-tree-sitter/dsl').SymbolRule<string>} symbol
@@ -1822,8 +1842,6 @@ function aliasWithAsyncKeyword(rule, symbol) {
1822
1842
  }
1823
1843
 
1824
1844
  /**
1825
- * Creates a rule to match one or more of the rules separated by a comma
1826
- *
1827
1845
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
1828
1846
  *
1829
1847
  * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
@@ -1833,8 +1851,6 @@ function commaSep1(rule) {
1833
1851
  }
1834
1852
 
1835
1853
  /**
1836
- * Creates a rule to optionally match one or more of the rules separated by a comma
1837
- *
1838
1854
  * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
1839
1855
  *
1840
1856
  * @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "16.0.0",
3
+ "version": "18.0.0",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -19,7 +19,6 @@
19
19
  "grammars/script/grammar.js",
20
20
  "grammars/script/src/node-types.json",
21
21
  "tree-sitter.json",
22
- "queries/*",
23
22
  "src/node-types.json",
24
23
  "*.wasm"
25
24
  ],
@@ -49,17 +48,17 @@
49
48
  "devDependencies": {
50
49
  "@babel/parser": "8.0.7",
51
50
  "@tsconfig/bun": "1.0.11",
52
- "@types/bun": "1.4.3",
51
+ "@types/bun": "1.4.4",
53
52
  "@vitest/browser-playwright": "5.0.5",
54
53
  "@willbooster/oxlint-config": "1.4.9",
55
- "@willbooster/wb": "22.29.3",
56
- "@willbooster/web-tree-sitter": "15.0.0",
54
+ "@willbooster/wb": "22.32.3",
55
+ "@willbooster/web-tree-sitter": "15.5.4",
57
56
  "acorn": "8.19.0",
58
57
  "acorn-jsx": "5.3.2",
59
58
  "conventional-changelog-conventionalcommits": "10.4.1",
60
59
  "lefthook": "2.2.2",
61
- "oxlint": "1.88.0",
62
- "oxlint-tsgolint": "7.0.2004",
60
+ "oxlint": "1.89.0",
61
+ "oxlint-tsgolint": "7.0.2005",
63
62
  "playwright": "1.64.1",
64
63
  "semantic-release": "25.0.9",
65
64
  "vite": "8.3.4",
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -11,14 +11,6 @@
11
11
  "mjs",
12
12
  "jsx"
13
13
  ],
14
- "highlights": [
15
- "queries/highlights.scm",
16
- "queries/highlights-jsx.scm",
17
- "queries/highlights-params.scm"
18
- ],
19
- "injections": "queries/injections.scm",
20
- "locals": "queries/locals.scm",
21
- "tags": "queries/tags.scm",
22
14
  "injection-regex": "^(js|javascript)$",
23
15
  "external-files": [
24
16
  "src/function_context.h"
@@ -32,14 +24,6 @@
32
24
  "file-types": [
33
25
  "cjs"
34
26
  ],
35
- "highlights": [
36
- "queries/highlights.scm",
37
- "queries/highlights-jsx.scm",
38
- "queries/highlights-params.scm"
39
- ],
40
- "injections": "queries/injections.scm",
41
- "locals": "queries/locals.scm",
42
- "tags": "queries/tags.scm",
43
27
  "injection-regex": "^javascript-script$",
44
28
  "external-files": [
45
29
  "src/scanner.c",
@@ -48,7 +32,7 @@
48
32
  }
49
33
  ],
50
34
  "metadata": {
51
- "version": "16.0.0",
35
+ "version": "18.0.0",
52
36
  "license": "MIT",
53
37
  "description": "JavaScript grammar for tree-sitter",
54
38
  "authors": [
@@ -1,8 +0,0 @@
1
- (jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
2
- (jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
3
- (jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
4
-
5
- (jsx_attribute (property_identifier) @attribute)
6
- (jsx_opening_element (["<" ">"]) @punctuation.bracket)
7
- (jsx_closing_element (["</" ">"]) @punctuation.bracket)
8
- (jsx_self_closing_element (["<" "/>"]) @punctuation.bracket)
@@ -1,12 +0,0 @@
1
- (formal_parameters
2
- [
3
- (identifier) @variable.parameter
4
- (array_pattern
5
- (identifier) @variable.parameter)
6
- (object_pattern
7
- [
8
- (pair_pattern value: (identifier) @variable.parameter)
9
- (shorthand_property_identifier_pattern) @variable.parameter
10
- ])
11
- ]
12
- )
@@ -1,216 +0,0 @@
1
- ; Variables
2
- ;----------
3
-
4
- (identifier) @variable
5
-
6
- ; Properties
7
- ;-----------
8
-
9
- (property_identifier) @property
10
-
11
- ; Function and method definitions
12
- ;--------------------------------
13
-
14
- (function_expression
15
- name: (identifier) @function)
16
- (function_declaration
17
- name: (identifier) @function)
18
- (method_definition
19
- name: (property_identifier) @function.method)
20
-
21
- (pair
22
- key: (property_identifier) @function.method
23
- value: [(function_expression) (arrow_function)])
24
-
25
- (assignment_expression
26
- left: (member_expression
27
- property: (property_identifier) @function.method)
28
- right: [(function_expression) (arrow_function)])
29
-
30
- (variable_declarator
31
- name: (identifier) @function
32
- value: [(function_expression) (arrow_function)])
33
-
34
- (assignment_expression
35
- left: (identifier) @function
36
- right: [(function_expression) (arrow_function)])
37
-
38
- ; Function and method calls
39
- ;--------------------------
40
-
41
- (call_expression
42
- function: (identifier) @function)
43
-
44
- (call_expression
45
- function: (member_expression
46
- property: (property_identifier) @function.method))
47
-
48
- ; Special identifiers
49
- ;--------------------
50
-
51
- ((identifier) @constructor
52
- (#match? @constructor "^[A-Z]"))
53
-
54
- ([
55
- (identifier)
56
- (shorthand_property_identifier)
57
- (shorthand_property_identifier_pattern)
58
- ] @constant
59
- (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
60
-
61
- ((identifier) @variable.builtin
62
- (#match? @variable.builtin "^(arguments|module|console|window|document)$"))
63
-
64
- ((identifier) @function.builtin
65
- (#eq? @function.builtin "require"))
66
-
67
- ; Literals
68
- ;---------
69
-
70
- (this) @variable.builtin
71
- (super) @variable.builtin
72
-
73
- [
74
- (true)
75
- (false)
76
- (null)
77
- (undefined)
78
- ] @constant.builtin
79
-
80
- (comment) @comment
81
-
82
- [
83
- (string)
84
- (template_string)
85
- ] @string
86
-
87
- (regex) @string.special
88
- (number) @number
89
-
90
- ; Tokens
91
- ;-------
92
-
93
- [
94
- ";"
95
- (optional_chain)
96
- "."
97
- ","
98
- ] @punctuation.delimiter
99
-
100
- [
101
- "-"
102
- "--"
103
- "-="
104
- "+"
105
- "++"
106
- "+="
107
- "*"
108
- "*="
109
- "**"
110
- "**="
111
- "/"
112
- "/="
113
- "%"
114
- "%="
115
- "<"
116
- "<="
117
- "<<"
118
- "<<="
119
- "="
120
- "=="
121
- "==="
122
- "!"
123
- "!="
124
- "!=="
125
- "=>"
126
- ">"
127
- ">="
128
- ">>"
129
- ">>="
130
- ">>>"
131
- ">>>="
132
- "~"
133
- "^"
134
- "&"
135
- "|"
136
- "^="
137
- "&="
138
- "|="
139
- "&&"
140
- "||"
141
- "??"
142
- "&&="
143
- "||="
144
- "??="
145
- ] @operator
146
-
147
- [
148
- "("
149
- ")"
150
- "["
151
- "]"
152
- "{"
153
- "}"
154
- ] @punctuation.bracket
155
-
156
- (template_substitution
157
- "${" @punctuation.special
158
- "}" @punctuation.special) @embedded
159
-
160
- [
161
- "as"
162
- "async"
163
- "await"
164
- "break"
165
- "case"
166
- "catch"
167
- "class"
168
- "const"
169
- "continue"
170
- "debugger"
171
- "default"
172
- "delete"
173
- "do"
174
- "else"
175
- "export"
176
- "extends"
177
- "finally"
178
- "for"
179
- "from"
180
- "function"
181
- "get"
182
- "if"
183
- "import"
184
- "in"
185
- "instanceof"
186
- "let"
187
- "new"
188
- "of"
189
- "return"
190
- "set"
191
- "static"
192
- "switch"
193
- "target"
194
- "throw"
195
- "try"
196
- "typeof"
197
- "var"
198
- "void"
199
- "while"
200
- "with"
201
- "yield"
202
- ] @keyword
203
-
204
- ; `default` as a module export name is an identifier node.
205
- (export_specifier
206
- name: (identifier) @keyword
207
- (#eq? @keyword "default"))
208
- (export_specifier
209
- alias: (identifier) @keyword
210
- (#eq? @keyword "default"))
211
- (import_specifier
212
- name: (identifier) @keyword
213
- (#eq? @keyword "default"))
214
- (namespace_export
215
- (identifier) @keyword
216
- (#eq? @keyword "default"))
@@ -1,31 +0,0 @@
1
- ; Parse the contents of tagged template literals using
2
- ; a language inferred from the tag.
3
-
4
- (call_expression
5
- function: [
6
- (identifier) @injection.language
7
- (member_expression
8
- property: (property_identifier) @injection.language)
9
- ]
10
- arguments: (template_string (string_fragment) @injection.content)
11
- (#set! injection.combined)
12
- (#set! injection.include-children))
13
-
14
-
15
- ; Parse regex syntax within regex literals
16
-
17
- ((regex_pattern) @injection.content
18
- (#set! injection.language "regex"))
19
-
20
- ; Parse JSDoc annotations in comments
21
-
22
- ((comment) @injection.content
23
- (#set! injection.language "jsdoc"))
24
-
25
- ; Parse Ember/Glimmer/Handlebars/HTMLBars/etc. template literals
26
- ; e.g.: await render(hbs`<SomeComponent />`)
27
- (call_expression
28
- function: ((identifier) @_name
29
- (#eq? @_name "hbs"))
30
- arguments: ((template_string) @glimmer
31
- (#offset! @glimmer 0 1 0 -1)))
@@ -1,23 +0,0 @@
1
- ; Scopes
2
- ;-------
3
-
4
- [
5
- (statement_block)
6
- (function_expression)
7
- (arrow_function)
8
- (function_declaration)
9
- (method_definition)
10
- ] @local.scope
11
-
12
- ; Definitions
13
- ;------------
14
-
15
- (pattern/identifier) @local.definition
16
-
17
- (variable_declarator
18
- name: (identifier) @local.definition)
19
-
20
- ; References
21
- ;------------
22
-
23
- (identifier) @local.reference
package/queries/tags.scm DELETED
@@ -1,115 +0,0 @@
1
- (
2
- (comment)* @doc
3
- .
4
- (method_definition
5
- name: (property_identifier) @name) @definition.method
6
- (#not-eq? @name "constructor")
7
- (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
8
- (#select-adjacent! @doc @definition.method)
9
- )
10
-
11
- (
12
- (comment)* @doc
13
- .
14
- [
15
- (class
16
- name: (_) @name)
17
- (class_declaration
18
- name: (_) @name)
19
- ] @definition.class
20
- (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
21
- (#select-adjacent! @doc @definition.class)
22
- )
23
-
24
- (
25
- (comment)* @doc
26
- .
27
- [
28
- (function_expression
29
- name: (identifier) @name)
30
- (function_declaration
31
- name: (identifier) @name)
32
- (generator_function
33
- name: (identifier) @name)
34
- (generator_function_declaration
35
- name: (identifier) @name)
36
- ] @definition.function
37
- (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
38
- (#select-adjacent! @doc @definition.function)
39
- )
40
-
41
- (
42
- (comment)* @doc
43
- .
44
- (lexical_declaration
45
- (variable_declarator
46
- name: (identifier) @name
47
- value: [(arrow_function) (function_expression)]) @definition.function)
48
- (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
49
- (#select-adjacent! @doc @definition.function)
50
- )
51
-
52
- (
53
- (comment)* @doc
54
- .
55
- (variable_declaration
56
- (variable_declarator
57
- name: (identifier) @name
58
- value: [(arrow_function) (function_expression)]) @definition.function)
59
- (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
60
- (#select-adjacent! @doc @definition.function)
61
- )
62
-
63
- (assignment_expression
64
- left: [
65
- (identifier) @name
66
- (member_expression
67
- property: (property_identifier) @name)
68
- ]
69
- right: [(arrow_function) (function_expression)]
70
- ) @definition.function
71
-
72
- (pair
73
- key: (property_identifier) @name
74
- value: [(arrow_function) (function_expression)]) @definition.function
75
-
76
- (
77
- (call_expression
78
- function: (identifier) @name) @reference.call
79
- (#not-match? @name "^(require)$")
80
- )
81
-
82
- (call_expression
83
- function: (member_expression
84
- property: (property_identifier) @name)
85
- arguments: (_)) @reference.call
86
-
87
- (new_expression
88
- constructor: (_) @name) @reference.class
89
-
90
- (
91
- [
92
- (jsx_opening_element name: (identifier) @name)
93
- (jsx_self_closing_element name: (identifier) @name)
94
- ] @reference.call
95
- (#not-match? @name "^[a-z]|-|\\\\")
96
- )
97
-
98
- (
99
- [
100
- (jsx_opening_element name: (member_expression property: (property_identifier) @name))
101
- (jsx_self_closing_element name: (member_expression property: (property_identifier) @name))
102
- ] @reference.call
103
- (#not-match? @name "\\\\")
104
- )
105
-
106
- (export_statement value: (assignment_expression left: (identifier) @name right: ([
107
- (number)
108
- (string)
109
- (identifier)
110
- (undefined)
111
- (null)
112
- (new_expression)
113
- (binary_expression)
114
- (call_expression)
115
- ]))) @definition.constant