@willbooster/tree-sitter-bash 1.1.4 → 2.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
@@ -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
@@ -40,8 +46,8 @@ script/parse-examples
40
46
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
41
47
  - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
42
48
  reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
43
- `TREE_SITTER_EDITS` run other or more edits;
44
- - the Node.js binding test;
49
+ `TREE_SITTER_EDITS` run other or more edits. It also applies edits that random ones rarely reach and compares each
50
+ incremental reparse with a fresh parse;
45
51
  - a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
46
52
  `script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
47
53
  pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -50,13 +56,12 @@ script/parse-examples
50
56
  scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
51
57
  bash runs, with as many words and the same value for each word without expansions, and that the tree has no
52
58
  `ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
53
- `DIFFERENTIAL_CASES` run other or more scripts. It loads the Node.js addon, which `bun run build/ci` rebuilds after
54
- regenerating the parser;
59
+ `DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through web-tree-sitter, which `bun run build/ci`
60
+ rebuilds after regenerating the parser;
55
61
  - a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
56
62
  parse untrusted scripts.
57
63
 
58
- CI also runs these tests on every platform that gets a prebuild, and fuzzes the parser with libFuzzer and sanitizers
59
- (`.github/workflows/robustness.yml`).
64
+ CI also fuzzes the parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
60
65
 
61
66
  ### References
62
67