@willbooster/tree-sitter-bash 1.0.1 → 1.1.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
@@ -35,14 +35,27 @@ const tree = parser.parse('cat <<EOF; echo done\n$(date)\nEOF\n');
35
35
  ```sh
36
36
  mise install
37
37
  bun install --frozen-lockfile
38
- bun run tree-sitter generate
38
+ bun run build/ci
39
39
  bun run test
40
40
  script/parse-examples
41
41
  ```
42
42
 
43
- `script/parse-examples` clones real-world scripts into `examples/`, parses them with the local
44
- tree-sitter CLI, and rewrites `script/known-failures.txt`, the list of files that fail to parse; its diff shows
45
- regressions.
43
+ `bun run test` runs:
44
+
45
+ - the corpus in `test/corpus`;
46
+ - the Node.js binding test;
47
+ - a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
48
+ `script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
49
+ pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
50
+ `script/parse-examples` rewrites it; review its diff before committing;
51
+ - a differential test (`test/unit/differential.test.ts`, with helpers in `test/helpers/differential`) that generates
52
+ scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
53
+ bash runs, with as many words and the same value for each word without expansions, and that the tree has no
54
+ `ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
55
+ `DIFFERENTIAL_CASES` run other or more scripts. It loads the Node.js addon, which `bun run build/ci` rebuilds after
56
+ regenerating the parser;
57
+ - a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
58
+ parse untrusted scripts.
46
59
 
47
60
  ### References
48
61
 
package/grammar.js CHANGED
@@ -96,6 +96,11 @@ module.exports = grammar({
96
96
  $._command_statement,
97
97
  ],
98
98
 
99
+ // Until `;;` or `esac`, a case item's statements may belong to a middle item or to the last one.
100
+ conflicts: $ => [
101
+ [$._statements, $._last_case_item],
102
+ ],
103
+
99
104
  word: $ => $.word,
100
105
 
101
106
  rules: {
@@ -425,8 +430,9 @@ module.exports = grammar({
425
430
  field('terminator', choice(';;', ';&', ';;&')),
426
431
  ),
427
432
 
428
- // Only the last item may omit its terminator.
429
- _last_case_item: $ => seq($._case_patterns, optional($._statements)),
433
+ // Only the last item may omit its terminator, but its statements still end before `esac`, which is
434
+ // otherwise an argument (`a) echo esac`).
435
+ _last_case_item: $ => seq($._case_patterns, optional($._terminated_statements)),
430
436
 
431
437
  _case_patterns: $ => seq(
432
438
  optional('('),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-bash",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Bash grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -28,7 +28,8 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "build-prebuilds": "prebuildify --napi --strip --name tree-sitter-bash",
31
- "build/ci": "tree-sitter generate",
31
+ "build-wasm": "tree-sitter build --wasm",
32
+ "build/ci": "tree-sitter generate && node-gyp rebuild",
32
33
  "cleanup": "bun wb lint --fix --format",
33
34
  "format": "bun wb lint --format",
34
35
  "install": "node-gyp-build",
@@ -37,9 +38,9 @@
37
38
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
38
39
  "release": "wb release",
39
40
  "release-test": "node node_modules/semantic-release/bin/semantic-release.js --dry-run --plugins @semantic-release/commit-analyzer @semantic-release/release-notes-generator",
40
- "prestart": "tree-sitter build --wasm",
41
+ "prestart": "bun run build-wasm",
41
42
  "start": "tree-sitter playground",
42
- "test": "tree-sitter test && node --test bindings/node/*_test.js",
43
+ "test": "bun wb test",
43
44
  "test/ci": "bun wb test-on-ci",
44
45
  "verify": "bun wb verify",
45
46
  "verify-full": "bun wb verify --full"
@@ -55,7 +56,7 @@
55
56
  "lefthook": "2.1.14",
56
57
  "node-gyp": "13.0.2",
57
58
  "prebuildify": "^6.0.1",
58
- "semantic-release": "25.0.5",
59
+ "semantic-release": "25.0.9",
59
60
  "sort-package-json": "4.0.0",
60
61
  "tree-sitter": "^0.25.0",
61
62
  "tree-sitter-cli": "^0.27.0"
package/src/grammar.json CHANGED
@@ -2193,7 +2193,7 @@
2193
2193
  "members": [
2194
2194
  {
2195
2195
  "type": "SYMBOL",
2196
- "name": "_statements"
2196
+ "name": "_terminated_statements"
2197
2197
  },
2198
2198
  {
2199
2199
  "type": "BLANK"
@@ -4612,7 +4612,12 @@
4612
4612
  "name": "_line_continuation"
4613
4613
  }
4614
4614
  ],
4615
- "conflicts": [],
4615
+ "conflicts": [
4616
+ [
4617
+ "_statements",
4618
+ "_last_case_item"
4619
+ ]
4620
+ ],
4616
4621
  "precedences": [],
4617
4622
  "externals": [
4618
4623
  {