@willbooster/tree-sitter-typescript 1.2.7 → 1.2.9

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-typescript/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-typescript/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-typescript/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-typescript/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.26.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.28.5-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-typescript.svg)](https://crates.io/crates/willbooster-tree-sitter-typescript)
10
10
 
11
11
  TypeScript and TSX grammars for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -102,31 +102,43 @@ script/parse-examples
102
102
  cargo test
103
103
  ```
104
104
 
105
+ `script/tree-sitter` (also `bun run tree-sitter`) runs the tree-sitter CLI of WillBooster/tree-sitter at the runtime
106
+ version locked in `Cargo.lock`, so the parsers are generated, built, tested, and fuzzed with the generator and the
107
+ runtime this package ships. The first run downloads that CLI from its GitHub Release into `.tmp/`, or builds it with
108
+ `cargo` (with the `cmake` that `mise.toml` pins) when the download fails or the release has no binary that runs here.
109
+
105
110
  `bun run test/ci-setup` installs Chromium for the browser tests. `bun run build/ci` regenerates `typescript/src/` and
106
111
  `tsx/src/` and builds both Wasm files. `bun run test` runs:
107
112
 
108
113
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK).
109
114
  Cases run with the `typescript` grammar unless they carry `:language(tsx)`;
110
115
  - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
111
- edits each corpus case of each grammar at random, reparses it, undoes the edits, and reparses again, on the
112
- WillBooster/tree-sitter runtime version locked in `Cargo.lock` (the first run downloads that CLI from its GitHub
113
- Release, or builds it with `cargo` when the download fails or the release has no binary that runs here).
116
+ edits each corpus case of each grammar at random, reparses it, undoes the edits, and reparses again.
114
117
  `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
115
118
  - a check that the real-world files in `examples/`, the checked-in ones and those of the cloned repositories, fail to
116
119
  parse exactly as listed in `script/known-failures.txt`. `.ts` files are parsed with the `typescript` grammar and
117
120
  `.tsx` files with the `tsx` grammar. The first run clones the repositories. The example repositories are pinned to
118
121
  commits in `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples`
119
122
  rewrites it; review its diff before committing;
120
- - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
121
- linear time with each grammar, since consumers parse files while they are being edited. It loads the Wasm builds
122
- through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parsers;
123
+ - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 20,000 lines takes
124
+ linear time with each grammar, measured in the parsing thread's CPU time, since consumers parse files while they are
125
+ being edited. It loads the Wasm builds through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after
126
+ regenerating the parsers;
123
127
  - a check (`test/unit/queries.test.ts`) that the queries `tree-sitter.json` lists compile against each grammar, are
124
128
  published in the npm package and the crate, and that `javascript/queries/` matches the queries of the installed
125
129
  @willbooster/tree-sitter-javascript; after updating that dependency, `script/copy-javascript-queries` refreshes the
126
130
  copies;
127
131
  - checks that both Wasm builds load and parse through @willbooster/web-tree-sitter in Chromium
128
132
  (`test/unit/browser/`) and in Cloudflare Workers with and without Node.js compatibility
129
- (`test/unit/workers.test.ts`, running the Worker in `test/fixtures/worker/`).
133
+ (`test/unit/workers.test.ts`, running the Worker in `test/fixtures/worker/`);
134
+ - a check (`test/unit/runtimeVersion.test.ts`) that `package.json` and `Cargo.lock` lock the same runtime version,
135
+ since the Wasm tests run on @willbooster/web-tree-sitter and the Rust tests, the fuzzing, and the CLI on the
136
+ willbooster-tree-sitter crate.
137
+
138
+ The tests compile the parsers into `.tmp/tree-sitter-lib` instead of the CLI's cache shared by every checkout;
139
+ `script/parse-examples` and `script/fuzz-corpus` build a parser of their own per run and delete it afterwards.
140
+ `mise.toml` sets `TREE_SITTER_LIBDIR` to `.tmp/tree-sitter-lib` as well, so other `tree-sitter` commands run in the
141
+ checkout use this checkout's parsers too.
130
142
 
131
143
  CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parsers natively, and fuzzes
132
144
  both parsers with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
@@ -248,13 +248,7 @@ module.exports = function defineGrammar(dialect) {
248
248
  )
249
249
  )
250
250
  ),
251
- prec(
252
- 'template_call',
253
- seq(
254
- field('function', choice($.primary_expression, alias($._argumentless_new_expression, $.new_expression))),
255
- field('arguments', $.template_string)
256
- )
257
- ),
251
+ prec('template_call', seq(field('function', $.primary_expression), field('arguments', $.template_string))),
258
252
  prec(
259
253
  'member',
260
254
  seq(
@@ -266,15 +260,14 @@ module.exports = function defineGrammar(dialect) {
266
260
  )
267
261
  ),
268
262
 
269
- // As in ECMAScript, a `new` with arguments is a member-level (primary) expression and one without them is not, so a
270
- // member access, a call, or a further argument list binds to the nearest `new` with arguments: `new new A().b`
271
- // constructs `new A().b`, and `new new A()(2)` constructs `new A()`.
263
+ // tree-sitter-javascript's two forms of `new`, with type arguments; its 'member' and 'new' precedences group nested
264
+ // `new` as ECMAScript does (`new new A().b` constructs `new A().b`), and both forms are primary expressions.
272
265
  new_expression: ($) =>
273
266
  prec(
274
267
  'new',
275
268
  seq(
276
269
  'new',
277
- field('constructor', $._new_constructor),
270
+ field('constructor', $.primary_expression),
278
271
  field('type_arguments', optional($.type_arguments)),
279
272
  field('arguments', $.arguments)
280
273
  )
@@ -283,12 +276,9 @@ module.exports = function defineGrammar(dialect) {
283
276
  _argumentless_new_expression: ($) =>
284
277
  prec.right(
285
278
  'new',
286
- seq('new', field('constructor', $._new_constructor), field('type_arguments', optional($.type_arguments)))
279
+ seq('new', field('constructor', $.primary_expression), field('type_arguments', optional($.type_arguments)))
287
280
  ),
288
281
 
289
- _new_constructor: ($) =>
290
- prec('new', choice($.primary_expression, alias($._argumentless_new_expression, $.new_expression))),
291
-
292
282
  assignment_expression: ($) =>
293
283
  prec.right(
294
284
  'assign',
@@ -299,20 +289,13 @@ module.exports = function defineGrammar(dialect) {
299
289
 
300
290
  _lhs_expression: ($, previous) => choice(previous, $.non_null_expression),
301
291
 
302
- primary_expression: ($, previous) => choice(previous, $.non_null_expression, $.new_expression),
292
+ primary_expression: ($, previous) => choice(previous, $.non_null_expression),
303
293
 
304
294
  // If the dialect is regular typescript, we exclude JSX expressions and
305
295
  // include type assertions. If the dialect is TSX, we do the opposite.
306
296
  expression: ($, previous) => {
307
- const choices = [
308
- $.as_expression,
309
- $.satisfies_expression,
310
- $.instantiation_expression,
311
- $.internal_module,
312
- alias($._argumentless_new_expression, $.new_expression),
313
- ];
314
- // A `new` with arguments is a primary expression (see new_expression).
315
- const members = previous.members.filter((member) => member.name !== 'new_expression');
297
+ const choices = [$.as_expression, $.satisfies_expression, $.instantiation_expression, $.internal_module];
298
+ const members = previous.members;
316
299
 
317
300
  if (dialect === 'typescript') {
318
301
  choices.push($.type_assertion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-typescript",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "TypeScript and TSX grammars for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -27,8 +27,8 @@
27
27
  "*.wasm"
28
28
  ],
29
29
  "scripts": {
30
- "build-wasm": "tree-sitter build --wasm typescript && tree-sitter build --wasm tsx",
31
- "build/ci": "tree-sitter generate typescript/grammar.js && tree-sitter generate tsx/grammar.js && bun run build-wasm",
30
+ "build-wasm": "script/tree-sitter build --wasm typescript && script/tree-sitter build --wasm tsx",
31
+ "build/ci": "script/tree-sitter generate typescript/grammar.js && script/tree-sitter generate tsx/grammar.js && bun run build-wasm",
32
32
  "cleanup": "bun wb lint --fix --format",
33
33
  "format": "bun wb lint --format",
34
34
  "lint": "bun wb lint",
@@ -36,10 +36,11 @@
36
36
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
37
37
  "release": "wb release",
38
38
  "prestart": "bun run build-wasm",
39
- "start": "tree-sitter playground",
39
+ "start": "script/tree-sitter playground",
40
40
  "test": "bun wb test",
41
41
  "test/ci": "bun wb test-on-ci",
42
42
  "test/ci-setup": "playwright install --with-deps chromium",
43
+ "tree-sitter": "script/tree-sitter",
43
44
  "typecheck": "bun wb typecheck",
44
45
  "verify": "bun wb verify",
45
46
  "verify-full": "bun wb verify --full"
@@ -50,9 +51,9 @@
50
51
  "@vitest/browser-playwright": "5.0.1",
51
52
  "@willbooster/oxfmt-config": "1.2.2",
52
53
  "@willbooster/oxlint-config": "1.4.8",
53
- "@willbooster/tree-sitter-javascript": "1.0.16",
54
- "@willbooster/wb": "22.13.0",
55
- "@willbooster/web-tree-sitter": "1.0.7",
54
+ "@willbooster/tree-sitter-javascript": "1.0.20",
55
+ "@willbooster/wb": "22.13.1",
56
+ "@willbooster/web-tree-sitter": "1.0.17",
56
57
  "conventional-changelog-conventionalcommits": "10.4.0",
57
58
  "lefthook": "2.1.14",
58
59
  "oxfmt": "0.70.0",
@@ -61,7 +62,6 @@
61
62
  "playwright": "1.63.0",
62
63
  "semantic-release": "25.0.9",
63
64
  "sort-package-json": "4.0.0",
64
- "tree-sitter-cli": "0.27.0",
65
65
  "typescript": "7.0.2",
66
66
  "vite": "8.3.0",
67
67
  "vitest": "5.0.1",
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -83,7 +83,7 @@
83
83
  }
84
84
  ],
85
85
  "metadata": {
86
- "version": "1.2.7",
86
+ "version": "1.2.9",
87
87
  "license": "MIT",
88
88
  "description": "TypeScript and TSX grammars for tree-sitter",
89
89
  "authors": [
@@ -105,10 +105,6 @@
105
105
  "type": "jsx_self_closing_element",
106
106
  "named": true
107
107
  },
108
- {
109
- "type": "new_expression",
110
- "named": true
111
- },
112
108
  {
113
109
  "type": "primary_expression",
114
110
  "named": true
@@ -97,10 +97,6 @@
97
97
  "type": "internal_module",
98
98
  "named": true
99
99
  },
100
- {
101
- "type": "new_expression",
102
- "named": true
103
- },
104
100
  {
105
101
  "type": "primary_expression",
106
102
  "named": true