@willbooster/tree-sitter-typescript 1.2.6 → 1.2.8
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 +20 -8
- package/common/defineGrammar.js +32 -17
- package/package.json +7 -7
- package/tree-sitter-tsx.wasm +0 -0
- package/tree-sitter-typescript.wasm +0 -0
- package/tree-sitter.json +1 -1
- package/tsx/src/node-types.json +5 -5
- package/typescript/src/node-types.json +5 -5
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-typescript/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-typescript/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](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` (which needs `cmake`) 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
|
|
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
|
|
121
|
-
linear time with each grammar, since consumers parse files while they are
|
|
122
|
-
through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after
|
|
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`).
|
package/common/defineGrammar.js
CHANGED
|
@@ -242,7 +242,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
242
242
|
prec(
|
|
243
243
|
'generic_call',
|
|
244
244
|
seq(
|
|
245
|
-
field('function',
|
|
245
|
+
field('function', $.primary_expression),
|
|
246
246
|
field('type_arguments', $.type_arguments),
|
|
247
247
|
field('arguments', choice($.arguments, $.template_string))
|
|
248
248
|
)
|
|
@@ -251,7 +251,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
251
251
|
prec(
|
|
252
252
|
'template_call',
|
|
253
253
|
seq(
|
|
254
|
-
field('function', choice($.primary_expression, $.new_expression)),
|
|
254
|
+
field('function', choice($.primary_expression, alias($._argumentless_new_expression, $.new_expression))),
|
|
255
255
|
field('arguments', $.template_string)
|
|
256
256
|
)
|
|
257
257
|
),
|
|
@@ -266,17 +266,29 @@ module.exports = function defineGrammar(dialect) {
|
|
|
266
266
|
)
|
|
267
267
|
),
|
|
268
268
|
|
|
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()`.
|
|
269
272
|
new_expression: ($) =>
|
|
270
|
-
prec
|
|
273
|
+
prec(
|
|
271
274
|
'new',
|
|
272
275
|
seq(
|
|
273
276
|
'new',
|
|
274
|
-
field('constructor', $.
|
|
277
|
+
field('constructor', $._new_constructor),
|
|
275
278
|
field('type_arguments', optional($.type_arguments)),
|
|
276
|
-
field('arguments',
|
|
279
|
+
field('arguments', $.arguments)
|
|
277
280
|
)
|
|
278
281
|
),
|
|
279
282
|
|
|
283
|
+
_argumentless_new_expression: ($) =>
|
|
284
|
+
prec.right(
|
|
285
|
+
'new',
|
|
286
|
+
seq('new', field('constructor', $._new_constructor), field('type_arguments', optional($.type_arguments)))
|
|
287
|
+
),
|
|
288
|
+
|
|
289
|
+
_new_constructor: ($) =>
|
|
290
|
+
prec('new', choice($.primary_expression, alias($._argumentless_new_expression, $.new_expression))),
|
|
291
|
+
|
|
280
292
|
assignment_expression: ($) =>
|
|
281
293
|
prec.right(
|
|
282
294
|
'assign',
|
|
@@ -287,18 +299,26 @@ module.exports = function defineGrammar(dialect) {
|
|
|
287
299
|
|
|
288
300
|
_lhs_expression: ($, previous) => choice(previous, $.non_null_expression),
|
|
289
301
|
|
|
290
|
-
primary_expression: ($, previous) => choice(previous, $.non_null_expression),
|
|
302
|
+
primary_expression: ($, previous) => choice(previous, $.non_null_expression, $.new_expression),
|
|
291
303
|
|
|
292
304
|
// If the dialect is regular typescript, we exclude JSX expressions and
|
|
293
305
|
// include type assertions. If the dialect is TSX, we do the opposite.
|
|
294
306
|
expression: ($, previous) => {
|
|
295
|
-
const choices = [
|
|
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');
|
|
296
316
|
|
|
297
317
|
if (dialect === 'typescript') {
|
|
298
318
|
choices.push($.type_assertion);
|
|
299
|
-
choices.push(...
|
|
319
|
+
choices.push(...members.filter((member) => member.name !== '_jsx_element'));
|
|
300
320
|
} else if (dialect === 'tsx') {
|
|
301
|
-
choices.push(...
|
|
321
|
+
choices.push(...members);
|
|
302
322
|
} else {
|
|
303
323
|
throw new Error(`Unknown dialect ${dialect}`);
|
|
304
324
|
}
|
|
@@ -419,7 +439,8 @@ module.exports = function defineGrammar(dialect) {
|
|
|
419
439
|
')'
|
|
420
440
|
),
|
|
421
441
|
|
|
422
|
-
|
|
442
|
+
// TypeScript parses a postfix `!` as part of a member access chain, so `new A!()` constructs `A!`.
|
|
443
|
+
non_null_expression: ($) => prec('member', seq($.primary_expression, '!')),
|
|
423
444
|
|
|
424
445
|
variable_declarator: ($) =>
|
|
425
446
|
choice(
|
|
@@ -565,13 +586,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
565
586
|
satisfies_expression: ($) => prec.left('binary', seq($.expression, 'satisfies', $.type)),
|
|
566
587
|
|
|
567
588
|
instantiation_expression: ($) =>
|
|
568
|
-
prec.dynamic(
|
|
569
|
-
-1,
|
|
570
|
-
prec(
|
|
571
|
-
'instantiation',
|
|
572
|
-
seq(choice($.primary_expression, $.new_expression), field('type_arguments', $.type_arguments))
|
|
573
|
-
)
|
|
574
|
-
),
|
|
589
|
+
prec.dynamic(-1, prec('instantiation', seq($.primary_expression, field('type_arguments', $.type_arguments)))),
|
|
575
590
|
|
|
576
591
|
class_heritage: ($) => choice(seq($.extends_clause, optional($.implements_clause)), $.implements_clause),
|
|
577
592
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-typescript",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
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"
|
|
@@ -51,8 +52,8 @@
|
|
|
51
52
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
52
53
|
"@willbooster/oxlint-config": "1.4.8",
|
|
53
54
|
"@willbooster/tree-sitter-javascript": "1.0.16",
|
|
54
|
-
"@willbooster/wb": "22.13.
|
|
55
|
-
"@willbooster/web-tree-sitter": "1.0.
|
|
55
|
+
"@willbooster/wb": "22.13.1",
|
|
56
|
+
"@willbooster/web-tree-sitter": "1.0.15",
|
|
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",
|
package/tree-sitter-tsx.wasm
CHANGED
|
Binary file
|
|
Binary file
|
package/tree-sitter.json
CHANGED
package/tsx/src/node-types.json
CHANGED
|
@@ -221,6 +221,10 @@
|
|
|
221
221
|
"type": "meta_property",
|
|
222
222
|
"named": true
|
|
223
223
|
},
|
|
224
|
+
{
|
|
225
|
+
"type": "new_expression",
|
|
226
|
+
"named": true
|
|
227
|
+
},
|
|
224
228
|
{
|
|
225
229
|
"type": "non_null_expression",
|
|
226
230
|
"named": true
|
|
@@ -3110,10 +3114,6 @@
|
|
|
3110
3114
|
"multiple": false,
|
|
3111
3115
|
"required": false,
|
|
3112
3116
|
"types": [
|
|
3113
|
-
{
|
|
3114
|
-
"type": "new_expression",
|
|
3115
|
-
"named": true
|
|
3116
|
-
},
|
|
3117
3117
|
{
|
|
3118
3118
|
"type": "primary_expression",
|
|
3119
3119
|
"named": true
|
|
@@ -4057,7 +4057,7 @@
|
|
|
4057
4057
|
"required": true,
|
|
4058
4058
|
"types": [
|
|
4059
4059
|
{
|
|
4060
|
-
"type": "
|
|
4060
|
+
"type": "primary_expression",
|
|
4061
4061
|
"named": true
|
|
4062
4062
|
}
|
|
4063
4063
|
]
|
|
@@ -217,6 +217,10 @@
|
|
|
217
217
|
"type": "meta_property",
|
|
218
218
|
"named": true
|
|
219
219
|
},
|
|
220
|
+
{
|
|
221
|
+
"type": "new_expression",
|
|
222
|
+
"named": true
|
|
223
|
+
},
|
|
220
224
|
{
|
|
221
225
|
"type": "non_null_expression",
|
|
222
226
|
"named": true
|
|
@@ -3106,10 +3110,6 @@
|
|
|
3106
3110
|
"multiple": false,
|
|
3107
3111
|
"required": false,
|
|
3108
3112
|
"types": [
|
|
3109
|
-
{
|
|
3110
|
-
"type": "new_expression",
|
|
3111
|
-
"named": true
|
|
3112
|
-
},
|
|
3113
3113
|
{
|
|
3114
3114
|
"type": "primary_expression",
|
|
3115
3115
|
"named": true
|
|
@@ -3808,7 +3808,7 @@
|
|
|
3808
3808
|
"required": true,
|
|
3809
3809
|
"types": [
|
|
3810
3810
|
{
|
|
3811
|
-
"type": "
|
|
3811
|
+
"type": "primary_expression",
|
|
3812
3812
|
"named": true
|
|
3813
3813
|
}
|
|
3814
3814
|
]
|