@willbooster/tree-sitter-bash 2.1.3 → 2.1.5

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
@@ -4,7 +4,7 @@
4
4
  [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-bash.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml)
6
6
  [![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)
7
- [![wbfy](https://img.shields.io/badge/wbfy-20.26.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
7
+ [![wbfy](https://img.shields.io/badge/wbfy-20.28.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
8
 
9
9
  Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
10
10
  [tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash). We are grateful to its authors and
@@ -75,13 +75,19 @@ bun run test
75
75
  script/parse-examples
76
76
  ```
77
77
 
78
+ The scripts and tests generate, build, test, and parse with `script/tree-sitter`, the tree-sitter CLI of the
79
+ WillBooster/tree-sitter runtime version that `package.json` pins as `@willbooster/web-tree-sitter`, since the generator
80
+ and the runtime of upstream's CLI are not the ones this package ships with. Its first run downloads that CLI from the
81
+ runtime's GitHub Release, or builds it with `cargo` (whose build runs the CMake that `mise.toml` pins) when the download fails or the release has no
82
+ binary that runs here. Run other CLI commands through it as well (e.g. `script/tree-sitter parse script.sh`).
83
+
78
84
  `bun run test` runs:
79
85
 
80
86
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
81
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
82
- reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
83
- `TREE_SITTER_EDITS` run other or more edits. It also applies edits that random ones rarely reach and compares each
84
- incremental reparse with a fresh parse;
87
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
88
+ edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
89
+ `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits. It also applies edits that random ones
90
+ rarely reach and compares each incremental reparse with a fresh parse;
85
91
  - a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
86
92
  `script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
87
93
  pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -92,12 +98,16 @@ script/parse-examples
92
98
  `ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
93
99
  `DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through @willbooster/web-tree-sitter, which
94
100
  `bun run build/ci` rebuilds after regenerating the parser;
95
- - a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
101
+ - a performance check (`test/unit/performance.test.ts`) that a long line parses in linear time, since consumers
96
102
  parse untrusted scripts;
97
103
  - checks that the Wasm build parses in Chromium (`test/unit/web.browser.test.ts`) and in Cloudflare Workers with and
98
104
  without Node.js compatibility (`test/unit/workers.test.ts`, with the Worker in `test/fixtures/worker`), loading it as
99
105
  the Usage section shows.
100
106
 
107
+ The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
108
+ by every checkout; `script/fuzz-corpus` and the targeted edits of the incremental check build a parser of their own
109
+ for each run and delete it afterwards.
110
+
101
111
  CI also fuzzes the parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
102
112
 
103
113
  ### References
package/grammar.js CHANGED
@@ -140,6 +140,8 @@ module.exports = grammar({
140
140
  $._closer_line_raw_string_content,
141
141
  $._closer_line_ansi_c_string_content,
142
142
  $._joined_comment,
143
+ $._backtick_comment,
144
+ $._backtick_comment_boundary,
143
145
  $.__error_recovery,
144
146
  ],
145
147
 
@@ -157,8 +159,6 @@ module.exports = grammar({
157
159
  rules: {
158
160
  program: ($) => optional($._statements),
159
161
 
160
- // Statements
161
-
162
162
  _statements: ($) => seq(repeat(seq($._statement, $._terminator)), $._statement, optional($._terminator)),
163
163
 
164
164
  _terminated_statements: ($) => repeat1(seq($._statement, $._terminator)),
@@ -224,15 +224,18 @@ module.exports = grammar({
224
224
  seq(field('body', choice($._compound_command, $.function_definition)), repeat1(field('redirect', $._redirect)))
225
225
  ),
226
226
 
227
- // Simple commands
228
-
229
227
  command: ($) =>
230
228
  prec.left(
231
229
  choice(
232
230
  seq(
233
231
  repeat($._command_prefix),
234
232
  field('name', $.command_name),
235
- repeat(choice(field('argument', $._argument), field('redirect', $._redirect)))
233
+ repeat(
234
+ seq(
235
+ optional($._backtick_comment_boundary),
236
+ choice(field('argument', $._argument), field('redirect', $._redirect))
237
+ )
238
+ )
236
239
  ),
237
240
  repeat1($._command_prefix)
238
241
  )
@@ -240,14 +243,19 @@ module.exports = grammar({
240
243
 
241
244
  _command_prefix: ($) => choice(field('assignment', $.variable_assignment), field('redirect', $._redirect)),
242
245
 
243
- command_name: ($) => $._word,
246
+ command_name: ($) => seq(optional($._backtick_comment_boundary), $._word),
244
247
 
245
248
  declaration_command: ($) =>
246
249
  prec.left(
247
250
  seq(
248
251
  repeat($._command_prefix),
249
252
  field('name', alias(choice('declare', 'typeset', 'export', 'readonly', 'local'), $.command_name)),
250
- repeat(choice(field('argument', choice($.variable_assignment, $._argument)), field('redirect', $._redirect)))
253
+ repeat(
254
+ seq(
255
+ optional($._backtick_comment_boundary),
256
+ choice(field('argument', choice($.variable_assignment, $._argument)), field('redirect', $._redirect))
257
+ )
258
+ )
251
259
  )
252
260
  ),
253
261
 
@@ -309,8 +317,6 @@ module.exports = grammar({
309
317
 
310
318
  array: ($) => seq(token.immediate('('), repeat($._argument), ')'),
311
319
 
312
- // Redirections
313
-
314
320
  _redirect: ($) => choice($.file_redirect, $.heredoc_redirect, $.herestring_redirect),
315
321
 
316
322
  file_redirect: ($) =>
@@ -346,8 +352,6 @@ module.exports = grammar({
346
352
  $.heredoc_end
347
353
  ),
348
354
 
349
- // Compound commands
350
-
351
355
  compound_statement: ($) => seq('{', optional($._terminated_statements), '}'),
352
356
 
353
357
  subshell: ($) => seq('(', optional($._statements), ')'),
@@ -440,7 +444,7 @@ module.exports = grammar({
440
444
  field('body', $.do_group)
441
445
  ),
442
446
 
443
- do_group: ($) => seq('do', optional($._terminated_statements), 'done'),
447
+ do_group: ($) => seq(optional($._backtick_comment_boundary), 'do', optional($._terminated_statements), 'done'),
444
448
 
445
449
  for_statement: ($) =>
446
450
  seq(
@@ -448,7 +452,14 @@ module.exports = grammar({
448
452
  field('variable', alias($.word, $.variable_name)),
449
453
  // Without a word list the separator is optional (`for i do …`); a newline may precede `in`.
450
454
  choice(
451
- seq(optional($._newline), 'in', repeat(field('value', $._argument)), $._terminator),
455
+ seq(
456
+ optional($._newline),
457
+ optional($._backtick_comment_boundary),
458
+ 'in',
459
+ repeat(seq(optional($._backtick_comment_boundary), field('value', $._argument))),
460
+ optional($._backtick_comment_boundary),
461
+ $._terminator
462
+ ),
452
463
  optional($._terminator)
453
464
  ),
454
465
  field('body', choice($.do_group, $.compound_statement))
@@ -474,6 +485,7 @@ module.exports = grammar({
474
485
  seq(
475
486
  'case',
476
487
  field('value', $._argument),
488
+ optional($._backtick_comment_boundary),
477
489
  'in',
478
490
  repeat($.case_item),
479
491
  optional(alias($._last_case_item, $.case_item)),
@@ -487,16 +499,21 @@ module.exports = grammar({
487
499
  _last_case_item: ($) => seq($._case_patterns, optional($._terminated_statements)),
488
500
 
489
501
  _case_patterns: ($) =>
490
- seq(optional('('), field('pattern', $._argument), repeat(seq('|', field('pattern', $._argument))), ')'),
502
+ seq(
503
+ optional($._backtick_comment_boundary),
504
+ optional('('),
505
+ field('pattern', $._argument),
506
+ repeat(seq('|', field('pattern', $._argument))),
507
+ ')'
508
+ ),
491
509
 
492
510
  function_definition: ($) =>
493
511
  seq(
494
512
  choice(seq('function', field('name', $.word), optional(seq('(', ')'))), seq(field('name', $.word), '(', ')')),
513
+ optional($._backtick_comment_boundary),
495
514
  field('body', $._compound_command)
496
515
  ),
497
516
 
498
- // Words
499
-
500
517
  _word: ($) => choice($._word_part, $.concatenation),
501
518
 
502
519
  // Outside command position a leading `!(` is a negated extglob group rather than `!` negating a
@@ -806,8 +823,6 @@ module.exports = grammar({
806
823
  seq('$[', $._bracket_substitution_start, optional($._arithmetic_expression), $._bracket_substitution_end, ']')
807
824
  ),
808
825
 
809
- // Arithmetic
810
-
811
826
  _arithmetic_expression: ($) =>
812
827
  choice(
813
828
  $.number,
@@ -895,8 +910,7 @@ module.exports = grammar({
895
910
 
896
911
  _arithmetic_parenthesized: ($) => seq('(', $._arithmetic_expression, ')'),
897
912
 
898
- // A comment on such a line also continues past each line continuation.
899
- comment: ($) => choice(token(prec(-10, /#.*/)), $._joined_comment),
913
+ comment: ($) => choice(token(prec(-10, /#.*/)), $._joined_comment, $._backtick_comment),
900
914
  },
901
915
  });
902
916
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-bash",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Bash 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
  "typecheck": "bun wb typecheck",
@@ -41,24 +41,24 @@
41
41
  "devDependencies": {
42
42
  "@tsconfig/bun": "1.0.11",
43
43
  "@types/bun": "1.4.2",
44
- "@vitest/browser-playwright": "5.0.1",
44
+ "@vitest/browser-playwright": "5.0.2",
45
45
  "@willbooster/oxfmt-config": "1.2.2",
46
46
  "@willbooster/oxlint-config": "1.4.8",
47
- "@willbooster/wb": "22.13.0",
48
- "@willbooster/web-tree-sitter": "1.0.7",
47
+ "@willbooster/wb": "22.18.0",
48
+ "@willbooster/web-tree-sitter": "1.0.17",
49
49
  "conventional-changelog-conventionalcommits": "10.4.0",
50
50
  "lefthook": "2.1.14",
51
51
  "oxfmt": "0.70.0",
52
52
  "oxlint": "1.85.0",
53
- "oxlint-tsgolint": "7.0.2002",
53
+ "oxlint-tsgolint": "7.0.2003",
54
54
  "playwright": "1.63.0",
55
55
  "semantic-release": "25.0.9",
56
56
  "sort-package-json": "4.0.0",
57
57
  "tree-sitter-cli": "0.27.0",
58
58
  "typescript": "7.0.2",
59
- "vite": "8.3.0",
60
- "vitest": "5.0.1",
61
- "wrangler": "4.136.2"
59
+ "vite": "8.3.1",
60
+ "vitest": "5.0.2",
61
+ "wrangler": "4.141.0"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@willbooster/web-tree-sitter": "^1.0.0"
Binary file
package/tree-sitter.json CHANGED
@@ -18,7 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "metadata": {
21
- "version": "2.1.3",
21
+ "version": "2.1.5",
22
22
  "license": "MIT",
23
23
  "description": "Bash grammar for tree-sitter",
24
24
  "authors": [