@willbooster/tree-sitter-embedded-template 6.0.0 → 8.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
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-embedded-template/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-embedded-template.svg)](https://crates.io/crates/willbooster-tree-sitter-embedded-template)
10
10
 
11
11
  Embedded template grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -13,14 +13,21 @@ Embedded template grammar for [tree-sitter](https://github.com/tree-sitter/tree-
13
13
  to its authors and contributors. This is not an official release of that project.
14
14
 
15
15
  It parses templating languages such as ERB and EJS, in which scripting code is embedded in text with the delimiters
16
- `<%` and `%>`. This fork extends upstream's version 0.25.0 grammar with EJS output-tag whitespace slurping
17
- and HTML/Perl injections for angle-delimited Embedded Perl tags.
16
+ `<%` and `%>`. This fork extends upstream's version 0.25.0 grammar with EJS output-tag whitespace slurping,
17
+ trimming closers on comments, and the `=%>` closer on statements.
18
18
  It generates the parser with the
19
19
  [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser loads only with that
20
20
  fork's runtime, version 15.0.0 or later in the 15.x series
21
21
  ([willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter),
22
22
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter)); upstream's runtime rejects it.
23
23
 
24
+ ## Support Scope
25
+
26
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
27
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
28
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
29
+ the trees that error recovery produces may change; such changes are released as new major versions.
30
+
24
31
  ## Usage
25
32
 
26
33
  The npm package ships `tree-sitter-embedded_template.wasm` for
@@ -66,32 +73,15 @@ const parser = new Parser();
66
73
  parser.setLanguage(await Language.load(grammar));
67
74
  ```
68
75
 
69
- The package also ships `grammar.js`, the queries in `queries/`, and the node types in `src/node-types.json`.
70
-
71
- For HTML Embedded Perl templates, select `queries/injections-ep.scm` (or `INJECTIONS_EP_QUERY` in Rust).
72
- CLI language discovery associates every `.ep` file with the `text.html.ep` scope, including non-HTML templates
73
- such as `mail.txt.ep`. The query always treats template content as HTML; configure a different content injection
74
- for non-HTML formats. The host must process combined injections and provide HTML and Perl parsers generated
75
- with WillBooster/tree-sitter, matching this runtime's ABI. Use `@willbooster/tree-sitter-html` or
76
- `willbooster-tree-sitter-html` for HTML. For Perl, check out this repository
77
- and [tree-sitter-perl/tree-sitter-perl](https://github.com/tree-sitter-perl/tree-sitter-perl). From the Perl checkout
78
- as the working directory, run `<embedded-template-checkout>/script/tree-sitter generate grammar.js`, replacing
79
- `<embedded-template-checkout>` with this repository's absolute checkout path. Then build the generated parser for
80
- your host and register it as `perl`. The npm package and Rust crate include neither this script nor a Perl parser.
81
- Upstream-generated parsers cannot load in this runtime.
82
- With these parsers configured, the query supports the existing angle-delimited tags, such as
83
- `<% my $name = "World"; %><p><%= $name %></p>`; it is not a full Mojo::Template parser.
84
- Perl lines beginning with `%`, template capture markers (`begin`/`end`), custom delimiters, and whitespace-trimming
85
- `=%>` on non-output directives are not supported.
76
+ The package also ships `grammar.js` and the node types in `src/node-types.json`.
86
77
 
87
78
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-embedded-template) and on
88
79
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
89
80
  fuzzed with:
90
81
 
91
- ```toml
92
- [dependencies]
93
- tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
94
- tree-sitter-embedded-template = { package = "willbooster-tree-sitter-embedded-template", version = "6" }
82
+ ```sh
83
+ cargo add willbooster-tree-sitter@15.0.0 --rename tree-sitter
84
+ cargo add willbooster-tree-sitter-embedded-template --rename tree-sitter-embedded-template
95
85
  ```
96
86
 
97
87
  ```rust
@@ -127,9 +117,6 @@ and the release build regenerate the parsers before compiling them.
127
117
  `bun run test` runs:
128
118
 
129
119
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
130
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
131
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
132
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
133
120
  - a check that the real-world ERB and EJS templates in `examples/` fail to parse exactly as listed in
134
121
  `script/known-failures.txt`, which is empty now. The first run clones the repositories. The example repositories are pinned to commits in
135
122
  `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites it;
@@ -144,8 +131,7 @@ and the release build regenerate the parsers before compiling them.
144
131
  Cloudflare Workers with and without Node.js compatibility (`test/e2e/workers.test.ts`).
145
132
 
146
133
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
147
- by every checkout; `script/fuzz-corpus` builds a parser of its own in `.tmp/fuzz` for each run and deletes it
148
- afterwards.
134
+ by every checkout.
149
135
 
150
136
  CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser natively, and fuzzes the parser
151
137
  with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -28,7 +28,7 @@ module.exports = grammar({
28
28
  directive: $ => seq(
29
29
  choice('<%', '<%_', '<%|', '<%~'),
30
30
  optional($.code),
31
- choice('%>', '-%>', '_%>'),
31
+ choice('%>', '-%>', '=%>', '_%>'),
32
32
  ),
33
33
 
34
34
  output_directive: $ => seq(
@@ -40,7 +40,7 @@ module.exports = grammar({
40
40
  comment_directive: $ => seq(
41
41
  '<%#',
42
42
  optional(alias($.code, $.comment)),
43
- '%>',
43
+ choice('%>', '-%>', '=%>', '_%>'),
44
44
  ),
45
45
 
46
46
  graphql_directive: $ => seq(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-embedded-template",
3
- "version": "6.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "Embedded template (ERB, EJS) grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "embedded-template",
@@ -16,7 +16,6 @@
16
16
  },
17
17
  "files": [
18
18
  "grammar.js",
19
- "queries/*.scm",
20
19
  "src/node-types.json",
21
20
  "tree-sitter.json",
22
21
  "*.wasm"
@@ -46,19 +45,19 @@
46
45
  },
47
46
  "devDependencies": {
48
47
  "@tsconfig/bun": "1.0.11",
49
- "@types/bun": "1.4.3",
48
+ "@types/bun": "1.4.4",
50
49
  "@vitest/browser-playwright": "5.0.5",
51
50
  "@willbooster/oxlint-config": "1.4.9",
52
- "@willbooster/wb": "22.29.3",
51
+ "@willbooster/wb": "23.0.2",
53
52
  "@willbooster/web-tree-sitter": "15.0.0",
54
53
  "conventional-changelog-conventionalcommits": "10.4.1",
55
54
  "lefthook": "2.2.2",
56
- "oxlint": "1.88.0",
57
- "oxlint-tsgolint": "7.0.2004",
55
+ "oxlint": "1.89.0",
56
+ "oxlint-tsgolint": "7.0.2005",
58
57
  "playwright": "1.64.1",
59
58
  "semantic-release": "25.0.9",
60
59
  "vitest": "5.0.5",
61
- "wrangler": "4.151.1"
60
+ "wrangler": "4.152.0"
62
61
  },
63
62
  "peerDependencies": {
64
63
  "@willbooster/web-tree-sitter": "^15.0.0"
Binary file
package/tree-sitter.json CHANGED
@@ -9,7 +9,6 @@
9
9
  "file-types": [
10
10
  "ejs"
11
11
  ],
12
- "injections": "queries/injections-ejs.scm",
13
12
  "injection-regex": "ejs"
14
13
  },
15
14
  {
@@ -20,7 +19,6 @@
20
19
  "file-types": [
21
20
  "erb"
22
21
  ],
23
- "injections": "queries/injections-erb.scm",
24
22
  "injection-regex": "erb"
25
23
  },
26
24
  {
@@ -31,7 +29,6 @@
31
29
  "file-types": [
32
30
  "etlua"
33
31
  ],
34
- "injections": "queries/injections-etlua.scm",
35
32
  "injection-regex": "etlua"
36
33
  },
37
34
  {
@@ -42,12 +39,11 @@
42
39
  "file-types": [
43
40
  "ep"
44
41
  ],
45
- "injections": "queries/injections-ep.scm",
46
42
  "injection-regex": "ep"
47
43
  }
48
44
  ],
49
45
  "metadata": {
50
- "version": "6.0.0",
46
+ "version": "8.0.0",
51
47
  "license": "MIT",
52
48
  "description": "Embedded template (ERB, EJS) grammar for tree-sitter",
53
49
  "authors": [
@@ -1,12 +0,0 @@
1
- (comment_directive) @comment
2
-
3
- [
4
- "<%#"
5
- "<%"
6
- "<%="
7
- "<%_"
8
- "<%-"
9
- "%>"
10
- "-%>"
11
- "_%>"
12
- ] @keyword
@@ -1,7 +0,0 @@
1
- ((content) @injection.content
2
- (#set! injection.language "html")
3
- (#set! injection.combined))
4
-
5
- ((code) @injection.content
6
- (#set! injection.language "javascript")
7
- (#set! injection.combined))
@@ -1,7 +0,0 @@
1
- ((content) @injection.content
2
- (#set! injection.language "html")
3
- (#set! injection.combined))
4
-
5
- ((code) @injection.content
6
- (#set! injection.language "perl")
7
- (#set! injection.combined))
@@ -1,7 +0,0 @@
1
- ((content) @injection.content
2
- (#set! injection.language "html")
3
- (#set! injection.combined))
4
-
5
- ((code) @injection.content
6
- (#set! injection.language "ruby")
7
- (#set! injection.combined))
@@ -1,7 +0,0 @@
1
- ((content) @injection.content
2
- (#set! injection.language "html")
3
- (#set! injection.combined))
4
-
5
- ((code) @injection.content
6
- (#set! injection.language "lua")
7
- (#set! injection.combined))