@willbooster/tree-sitter-bash 1.1.3 → 2.0.0

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.20.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
7
+ [![wbfy](https://img.shields.io/badge/wbfy-20.23.2-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
@@ -16,15 +16,21 @@ As a result, its syntax trees differ from the original grammar's; review your qu
16
16
 
17
17
  ## Usage
18
18
 
19
+ The npm package ships `tree-sitter-bash.wasm` for [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter):
20
+
19
21
  ```js
20
- const Parser = require('tree-sitter');
21
- const Bash = require('@willbooster/tree-sitter-bash');
22
+ import { fileURLToPath } from 'node:url';
23
+ import { Language, Parser } from 'web-tree-sitter';
22
24
 
25
+ await Parser.init();
23
26
  const parser = new Parser();
24
- parser.setLanguage(Bash);
27
+ const wasmPath = fileURLToPath(import.meta.resolve('@willbooster/tree-sitter-bash/tree-sitter-bash.wasm'));
28
+ parser.setLanguage(await Language.load(wasmPath));
25
29
  const tree = parser.parse('cat <<EOF; echo done\n$(date)\nEOF\n');
26
30
  ```
27
31
 
32
+ The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
33
+
28
34
  ## Development
29
35
 
30
36
  ```sh
@@ -37,8 +43,10 @@ script/parse-examples
37
43
 
38
44
  `bun run test` runs:
39
45
 
40
- - the corpus in `test/corpus`;
41
- - the Node.js binding test;
46
+ - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
47
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
48
+ reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
49
+ `TREE_SITTER_EDITS` run other or more edits;
42
50
  - a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
43
51
  `script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
44
52
  pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -47,11 +55,14 @@ script/parse-examples
47
55
  scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
48
56
  bash runs, with as many words and the same value for each word without expansions, and that the tree has no
49
57
  `ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
50
- `DIFFERENTIAL_CASES` run other or more scripts. It loads the Node.js addon, which `bun run build/ci` rebuilds after
51
- regenerating the parser;
58
+ `DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through web-tree-sitter, which `bun run build/ci`
59
+ rebuilds after regenerating the parser;
52
60
  - a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
53
61
  parse untrusted scripts.
54
62
 
63
+ CI also runs these tests on Linux arm64 and macOS, and fuzzes the parser with libFuzzer and sanitizers
64
+ (`.github/workflows/robustness.yml`).
65
+
55
66
  ### References
56
67
 
57
68
  - [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)