@willbooster/tree-sitter-kotlin 9.0.4 → 10.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
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-kotlin/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-kotlin/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-21.3.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-kotlin.svg)](https://crates.io/crates/willbooster-tree-sitter-kotlin)
10
10
 
11
11
  Kotlin grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -14,11 +14,18 @@ to its authors and contributors. This is not an official release of that project
14
14
 
15
15
  This fork fixes parsing bugs and raises conformance with the Kotlin grammar.
16
16
 
17
+ ## Support Scope
18
+
19
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
20
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
21
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
22
+ the trees that error recovery produces may change; such changes are released as new major versions.
23
+
17
24
  ## Usage
18
25
 
19
26
  The npm package ships `tree-sitter-kotlin.wasm` for
20
27
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
21
- browsers, and Cloudflare Workers. The parser loads only with this runtime, version 15.0.0 or later in the 15.x series: the upstream
28
+ browsers, and Cloudflare Workers. The parser loads only with this runtime, version 15.0.0 or later in the 15.x or 16.x series: the upstream
22
29
  Tree-sitter runtime rejects it.
23
30
 
24
31
  In Node.js and Bun:
@@ -64,12 +71,11 @@ The package also ships the node types in `src/node-types.json`.
64
71
 
65
72
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-kotlin) and on
66
73
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
67
- fuzzed with. The parser loads only with this runtime, version 15.0.0 or later in the 15.x series:
74
+ fuzzed with. The parser loads only with this runtime, version 15.0.0 or later in the 15.x or 16.x series:
68
75
 
69
- ```toml
70
- [dependencies]
71
- tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
72
- tree-sitter-kotlin = { package = "willbooster-tree-sitter-kotlin", version = "9" }
76
+ ```sh
77
+ cargo add willbooster-tree-sitter@16.0.0 --rename tree-sitter
78
+ cargo add willbooster-tree-sitter-kotlin --rename tree-sitter-kotlin
73
79
  ```
74
80
 
75
81
  ```rust
@@ -104,9 +110,6 @@ and the release build regenerate the parsers before compiling them.
104
110
  `bun run test` runs:
105
111
 
106
112
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
107
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
108
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
109
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
110
113
  - a check that real-world Kotlin files cloned into `examples/` fail to parse exactly as listed in
111
114
  `script/known-failures.txt`. The first run clones them. The example repositories are pinned to commits in
112
115
  `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
@@ -121,8 +124,7 @@ and the release build regenerate the parsers before compiling them.
121
124
  (`test/unit/workers.test.ts`).
122
125
 
123
126
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
124
- by every checkout, and `mise.toml` sets `TREE_SITTER_LIBDIR` to it for any other command run in the checkout;
125
- `script/fuzz-corpus` builds a parser of its own in `.tmp/fuzz` for each run and deletes it afterwards.
127
+ by every checkout, and `mise.toml` sets `TREE_SITTER_LIBDIR` to it for any other command run in the checkout.
126
128
 
127
129
  CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the
128
130
  parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -30,6 +30,11 @@ module.exports = grammar({
30
30
  name: 'kotlin',
31
31
 
32
32
  conflicts: ($) => [
33
+ [$._positional_destructuring_entry, $.type_modifiers, $.annotated_expression],
34
+ [$._positional_destructuring_entry, $.primary_expression],
35
+ [$._mutable_positional_entry, $._immutable_positional_entry],
36
+ [$._mutable_named_entry, $._immutable_named_entry],
37
+ [$._named_destructuring_entry, $.type_modifiers, $.annotated_expression],
33
38
  [$.if_expression, $.parenthesized_expression],
34
39
  [$.class_body, $.enum_class_body],
35
40
 
@@ -378,7 +383,45 @@ module.exports = grammar({
378
383
 
379
384
  multi_variable_declaration: ($) => $._multi_variable_declaration,
380
385
 
381
- _multi_variable_declaration: ($) => seq('(', optionalCommaSep1($.variable_declaration), ')'),
386
+ _multi_variable_declaration: ($) =>
387
+ choice(
388
+ seq('(', optionalCommaSep1(alias($._named_destructuring_entry, $.variable_declaration)), ')'),
389
+ seq('[', commaSep1(alias($._positional_destructuring_entry, $.variable_declaration)), optional(','), ']')
390
+ ),
391
+
392
+ _positional_destructuring_entry: ($) => seq(repeat($.annotation), $._identifier, optional(seq(':', $.type))),
393
+
394
+ _named_destructuring_entry: ($) =>
395
+ prec(1, seq(repeat($.annotation), $._identifier, optional(seq(':', $.type)), optional(seq('=', $._identifier)))),
396
+
397
+ destructuring_declaration: ($) =>
398
+ seq(
399
+ optional($.modifiers),
400
+ alias($._mutable_destructuring, $.multi_variable_declaration),
401
+ optional(seq('=', $.expression))
402
+ ),
403
+
404
+ _mutable_destructuring: ($) =>
405
+ choice(
406
+ seq('(', commaSep1(alias($._mutable_named_entry, $.variable_declaration)), optional(','), ')'),
407
+ seq('[', commaSep1(alias($._mutable_positional_entry, $.variable_declaration)), optional(','), ']')
408
+ ),
409
+
410
+ _mutable_named_entry: ($) =>
411
+ seq(choice('val', 'var'), $._identifier, optional(seq(':', $.type)), optional(seq('=', $._identifier))),
412
+
413
+ _mutable_positional_entry: ($) => seq(choice('val', 'var'), $._identifier, optional(seq(':', $.type))),
414
+
415
+ _immutable_destructuring: ($) =>
416
+ choice(
417
+ seq('(', commaSep1(alias($._immutable_named_entry, $.variable_declaration)), optional(','), ')'),
418
+ seq('[', commaSep1(alias($._immutable_positional_entry, $.variable_declaration)), optional(','), ']')
419
+ ),
420
+
421
+ _immutable_named_entry: ($) =>
422
+ seq('val', $._identifier, optional(seq(':', $.type)), optional(seq('=', $._identifier))),
423
+
424
+ _immutable_positional_entry: ($) => seq('val', $._identifier, optional(seq(':', $.type))),
382
425
 
383
426
  property_delegate: ($) => seq('by', $.expression),
384
427
 
@@ -423,7 +466,11 @@ module.exports = grammar({
423
466
  'for',
424
467
  '(',
425
468
  repeat($.annotation),
426
- choice($.variable_declaration, $.multi_variable_declaration),
469
+ choice(
470
+ $.variable_declaration,
471
+ $.multi_variable_declaration,
472
+ alias($._immutable_destructuring, $.multi_variable_declaration)
473
+ ),
427
474
  'in',
428
475
  $.expression,
429
476
  ')',
@@ -496,7 +543,15 @@ module.exports = grammar({
496
543
  _statements: ($) => seq($.statement, repeat(seq(sym('_semi'), $.statement)), optional(sym('_semi'))),
497
544
 
498
545
  statement: ($) =>
499
- choice($.declaration, $.assignment, $.for_statement, $.while_statement, $.do_while_statement, $.expression),
546
+ choice(
547
+ $.declaration,
548
+ $.destructuring_declaration,
549
+ $.assignment,
550
+ $.for_statement,
551
+ $.while_statement,
552
+ $.do_while_statement,
553
+ $.expression
554
+ ),
500
555
 
501
556
  // Modifiers before a declaration may also read as an annotated expression statement (`@A (b)`) or, for modifier
502
557
  // keywords that `_reserved_identifier` accepts, as names, and both readings parse, so the one in which they modify
@@ -775,7 +830,7 @@ module.exports = grammar({
775
830
 
776
831
  _destructuring_lambda_parameter: ($) =>
777
832
  seq(
778
- $._multi_variable_declaration,
833
+ choice($._multi_variable_declaration, $._immutable_destructuring),
779
834
  optional(seq(alias(sym('_destructuring_type_start'), ':'), field('type', $.type)))
780
835
  ),
781
836
 
@@ -1097,9 +1152,7 @@ function optionalCommaSep1(rule) {
1097
1152
  }
1098
1153
 
1099
1154
  /**
1100
- * Creates the arguments of a call or an annotation. Whether a call takes a trailing lambda depends on the token after
1101
- * its arguments, which the lookahead of the scanned `)` reaches, so an edit there makes incremental parsing reparse the
1102
- * call instead of reusing a call without the lambda.
1155
+ * Creates the arguments of a call or an annotation, ending them with the scanner's `)` token.
1103
1156
  *
1104
1157
  * @param {GrammarSymbols} $
1105
1158
  * @param {RuleOrLiteral} open
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-kotlin",
3
- "version": "9.0.4",
3
+ "version": "10.0.1",
4
4
  "description": "Kotlin grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -45,23 +45,23 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@tsconfig/bun": "1.0.11",
48
- "@types/bun": "1.4.3",
48
+ "@types/bun": "1.4.4",
49
49
  "@vitest/browser-playwright": "5.0.5",
50
50
  "@willbooster/oxlint-config": "1.4.9",
51
- "@willbooster/wb": "22.29.3",
52
- "@willbooster/web-tree-sitter": "15.0.0",
51
+ "@willbooster/wb": "23.0.2",
52
+ "@willbooster/web-tree-sitter": "16.0.2",
53
53
  "conventional-changelog-conventionalcommits": "10.4.1",
54
54
  "lefthook": "2.2.2",
55
- "oxlint": "1.88.0",
56
- "oxlint-tsgolint": "7.0.2004",
55
+ "oxlint": "1.89.0",
56
+ "oxlint-tsgolint": "7.0.2005",
57
57
  "playwright": "1.64.1",
58
58
  "semantic-release": "25.0.9",
59
- "vite": "8.3.4",
59
+ "vite": "8.3.5",
60
60
  "vitest": "5.0.5",
61
- "wrangler": "4.151.1"
61
+ "wrangler": "4.152.0"
62
62
  },
63
63
  "peerDependencies": {
64
- "@willbooster/web-tree-sitter": "^15.0.0"
64
+ "@willbooster/web-tree-sitter": "^15.0.0 || ^16.0.0"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@willbooster/web-tree-sitter": {
@@ -211,6 +211,10 @@
211
211
  "type": "declaration",
212
212
  "named": true
213
213
  },
214
+ {
215
+ "type": "destructuring_declaration",
216
+ "named": true
217
+ },
214
218
  {
215
219
  "type": "do_while_statement",
216
220
  "named": true
@@ -955,6 +959,29 @@
955
959
  ]
956
960
  }
957
961
  },
962
+ {
963
+ "type": "destructuring_declaration",
964
+ "named": true,
965
+ "fields": {},
966
+ "children": {
967
+ "multiple": true,
968
+ "required": true,
969
+ "types": [
970
+ {
971
+ "type": "expression",
972
+ "named": true
973
+ },
974
+ {
975
+ "type": "modifiers",
976
+ "named": true
977
+ },
978
+ {
979
+ "type": "multi_variable_declaration",
980
+ "named": true
981
+ }
982
+ ]
983
+ }
984
+ },
958
985
  {
959
986
  "type": "do_while_statement",
960
987
  "named": true,
Binary file
package/tree-sitter.json CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
  ],
15
15
  "metadata": {
16
- "version": "9.0.4",
16
+ "version": "10.0.1",
17
17
  "license": "MIT",
18
18
  "description": "Kotlin grammar for tree-sitter",
19
19
  "authors": [