@willbooster/tree-sitter-javascript 1.0.18 → 1.0.20

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.28.6-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.28.7-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
@@ -88,13 +88,16 @@ script/parse-examples
88
88
  cargo test
89
89
  ```
90
90
 
91
+ Every `tree-sitter` command, from `generate` to the tests, runs the CLI of the WillBooster/tree-sitter runtime version
92
+ locked in `Cargo.lock` (`script/tree-sitter`), whose generator and runtime have fixes that the upstream CLI lacks.
93
+ `script/fork-cli` downloads that CLI into `.tmp/` from its GitHub Release on first use, or builds it with `cargo` when
94
+ the download fails or the release has no binary that runs here.
95
+
91
96
  `bun run test` runs:
92
97
 
93
98
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
94
99
  - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
95
- edits each corpus case at random, reparses it, undoes the edits, and reparses again, on the WillBooster/tree-sitter
96
- runtime version locked in `Cargo.lock` (the first run downloads that CLI from its GitHub Release, or builds it with
97
- `cargo` when the download fails or the release has no binary that runs here). `TREE_SITTER_SEED`,
100
+ edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
98
101
  `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
99
102
  - a check that the real-world JavaScript files in `examples/`, the checked-in ones and those of the cloned repository,
100
103
  fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repository. The example
@@ -113,7 +116,8 @@ cargo test
113
116
  the crate (`test/unit/queries.test.ts`).
114
117
 
115
118
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` instead of the CLI's cache shared
116
- by every checkout; `script/fuzz-corpus` builds a per-run parser in `.tmp/fuzz` and deletes it afterwards.
119
+ by every checkout, and `mise.toml` sets `TREE_SITTER_LIBDIR` to it for any other command run in the checkout;
120
+ `script/fuzz-corpus` builds a parser of its own in `.tmp/fuzz` for each run and deletes it afterwards.
117
121
 
118
122
  CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
119
123
  parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -500,7 +500,6 @@ module.exports = grammar({
500
500
  $.binary_expression,
501
501
  $.ternary_expression,
502
502
  $.update_expression,
503
- $.new_expression,
504
503
  $.yield_expression
505
504
  ),
506
505
 
@@ -527,7 +526,9 @@ module.exports = grammar({
527
526
  $.generator_function,
528
527
  $.class,
529
528
  $.meta_property,
530
- $.call_expression
529
+ $.call_expression,
530
+ $.new_expression,
531
+ alias($._argumentless_new_expression, $.new_expression)
531
532
  ),
532
533
 
533
534
  yield_expression: ($) =>
@@ -789,10 +790,7 @@ module.exports = grammar({
789
790
  call_expression: ($) =>
790
791
  choice(
791
792
  prec('call', seq(field('function', choice($.expression, $.import)), field('arguments', $.arguments))),
792
- prec(
793
- 'template_call',
794
- seq(field('function', choice($.primary_expression, $.new_expression)), field('arguments', $.template_string))
795
- ),
793
+ prec('template_call', seq(field('function', $.primary_expression), field('arguments', $.template_string))),
796
794
  prec(
797
795
  'member',
798
796
  seq(
@@ -803,15 +801,15 @@ module.exports = grammar({
803
801
  )
804
802
  ),
805
803
 
804
+ // As in ECMAScript, a member access or index extends the nearest `new` with arguments, while an argument list fills
805
+ // the nearest `new` that still lacks one: `new new A().b` constructs `new A().b`, `new new A().b(2)` constructs
806
+ // `new A().b` with `2`, and `new new A()(2)` constructs `new A()`. The 'member' and 'new' precedences make the parser
807
+ // shift a `.`, `[`, or argument list after a constructor rather than end a `new` without arguments, so that form
808
+ // never takes one. Both forms are primary expressions, so a nested `new` matches the constructor field's type.
806
809
  new_expression: ($) =>
807
- prec.right(
808
- 'new',
809
- seq(
810
- 'new',
811
- field('constructor', choice($.primary_expression, $.new_expression)),
812
- field('arguments', optional(prec.dynamic(1, $.arguments)))
813
- )
814
- ),
810
+ prec('new', seq('new', field('constructor', $.primary_expression), field('arguments', $.arguments))),
811
+
812
+ _argumentless_new_expression: ($) => prec.right('new', seq('new', field('constructor', $.primary_expression))),
815
813
 
816
814
  await_expression: ($) => prec.dynamic(2, prec('unary_void', seq('await', $.expression))),
817
815
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -22,8 +22,8 @@
22
22
  "*.wasm"
23
23
  ],
24
24
  "scripts": {
25
- "build-wasm": "tree-sitter build --wasm",
26
- "build/ci": "tree-sitter generate && tree-sitter build --wasm",
25
+ "build-wasm": "script/tree-sitter build --wasm",
26
+ "build/ci": "script/tree-sitter generate && script/tree-sitter build --wasm",
27
27
  "cleanup": "bun wb lint --fix --format",
28
28
  "format": "bun wb lint --format",
29
29
  "lint": "bun wb lint",
@@ -31,7 +31,7 @@
31
31
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
32
32
  "release": "wb release",
33
33
  "prestart": "bun run build-wasm",
34
- "start": "tree-sitter playground",
34
+ "start": "script/tree-sitter playground",
35
35
  "test": "bun wb test",
36
36
  "test/ci": "bun wb test-on-ci",
37
37
  "test/ci-setup": "playwright install --with-deps chromium",
@@ -46,7 +46,7 @@
46
46
  "@willbooster/oxfmt-config": "1.2.2",
47
47
  "@willbooster/oxlint-config": "1.4.8",
48
48
  "@willbooster/wb": "22.13.1",
49
- "@willbooster/web-tree-sitter": "1.0.12",
49
+ "@willbooster/web-tree-sitter": "1.0.16",
50
50
  "conventional-changelog-conventionalcommits": "10.4.0",
51
51
  "lefthook": "2.1.14",
52
52
  "oxfmt": "0.70.0",
@@ -57,10 +57,6 @@
57
57
  "type": "jsx_self_closing_element",
58
58
  "named": true
59
59
  },
60
- {
61
- "type": "new_expression",
62
- "named": true
63
- },
64
60
  {
65
61
  "type": "primary_expression",
66
62
  "named": true
@@ -165,6 +161,10 @@
165
161
  "type": "meta_property",
166
162
  "named": true
167
163
  },
164
+ {
165
+ "type": "new_expression",
166
+ "named": true
167
+ },
168
168
  {
169
169
  "type": "null",
170
170
  "named": true
@@ -2236,10 +2236,6 @@
2236
2236
  "multiple": false,
2237
2237
  "required": true,
2238
2238
  "types": [
2239
- {
2240
- "type": "new_expression",
2241
- "named": true
2242
- },
2243
2239
  {
2244
2240
  "type": "primary_expression",
2245
2241
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "1.0.18",
27
+ "version": "1.0.20",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [