@willbooster/tree-sitter-javascript 23.0.0 → 25.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 +5 -5
- package/package.json +3 -4
- package/src/literal.h +32 -28
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter-javascript_script.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ This fork fixes parsing bugs and raises conformance with [ECMAScript (ECMA-262)]
|
|
|
18
18
|
## Support Scope
|
|
19
19
|
|
|
20
20
|
This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
|
|
21
|
-
nodes without crashing, hanging, or taking more than linear time. Incremental parsing
|
|
22
|
-
|
|
21
|
+
nodes without crashing, hanging, or taking more than linear time. Incremental parsing is not supported, and no queries
|
|
22
|
+
(highlights, locals, injections, tags) are shipped. Node types, field names, and
|
|
23
23
|
the trees that error recovery produces may change; such changes are released as new major versions.
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
@@ -27,7 +27,7 @@ the trees that error recovery produces may change; such changes are released as
|
|
|
27
27
|
The npm package ships two languages for
|
|
28
28
|
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
|
|
29
29
|
browsers, and Cloudflare Workers. The parser carries the ABI number of WillBooster/tree-sitter (`0x5742000c`), so it
|
|
30
|
-
requires that runtime ABI; the upstream runtime rejects it. This package is tested with runtime
|
|
30
|
+
requires that runtime ABI; the upstream runtime rejects it. This package is tested with runtime 20.0.0, and its optional peer dependency requires 20.0.0 or later within 20.x. In Node.js and Bun, load it from
|
|
31
31
|
the package. Choose `tree-sitter-javascript.wasm` for the Module goal, or
|
|
32
32
|
`tree-sitter-javascript_script.wasm` for the Script goal. The source goal comes from the host or file type;
|
|
33
33
|
`.mjs` uses Module and `.cjs` uses Script, while `.js` depends on the host. For example, `await\nvalue` is one
|
|
@@ -81,10 +81,10 @@ array/formal and object-rest extension hooks. Their external scanners can includ
|
|
|
81
81
|
characters and escapes and JSX text for the tokens they pass it. The crate ships `tree-sitter.json` too.
|
|
82
82
|
|
|
83
83
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-javascript) and the
|
|
84
|
-
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime with the matching ABI. The tested version is
|
|
84
|
+
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime with the matching ABI. The tested version is 20.0.0:
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
|
-
cargo add willbooster-tree-sitter@
|
|
87
|
+
cargo add willbooster-tree-sitter@20.0.0 --rename tree-sitter
|
|
88
88
|
cargo add willbooster-tree-sitter-javascript --rename tree-sitter-javascript
|
|
89
89
|
```
|
|
90
90
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-javascript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "25.0.0",
|
|
4
4
|
"description": "JavaScript grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"incremental",
|
|
7
6
|
"javascript",
|
|
8
7
|
"parsing",
|
|
9
8
|
"tree-sitter"
|
|
@@ -53,7 +52,7 @@
|
|
|
53
52
|
"@vitest/browser-playwright": "5.0.5",
|
|
54
53
|
"@willbooster/oxlint-config": "1.4.9",
|
|
55
54
|
"@willbooster/wb": "23.3.0",
|
|
56
|
-
"@willbooster/web-tree-sitter": "
|
|
55
|
+
"@willbooster/web-tree-sitter": "20.0.0",
|
|
57
56
|
"acorn": "8.19.0",
|
|
58
57
|
"acorn-jsx": "5.3.2",
|
|
59
58
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
@@ -67,7 +66,7 @@
|
|
|
67
66
|
"wrangler": "4.156.0"
|
|
68
67
|
},
|
|
69
68
|
"peerDependencies": {
|
|
70
|
-
"@willbooster/web-tree-sitter": "^
|
|
69
|
+
"@willbooster/web-tree-sitter": "^20.0.0"
|
|
71
70
|
},
|
|
72
71
|
"peerDependenciesMeta": {
|
|
73
72
|
"@willbooster/web-tree-sitter": {
|
package/src/literal.h
CHANGED
|
@@ -7,21 +7,23 @@ static bool scan_character_reference(TSLexer *lexer);
|
|
|
7
7
|
static bool scan_template_escape_value(TSLexer *lexer);
|
|
8
8
|
static bool scan_fixed_hex_digits(TSLexer *lexer, unsigned length);
|
|
9
9
|
static bool scan_template_code_point(TSLexer *lexer);
|
|
10
|
-
static int hex_digit_value(int32_t c);
|
|
11
|
-
static bool is_ascii_letter(int32_t c);
|
|
12
|
-
static bool is_ascii_digit(int32_t c);
|
|
13
|
-
static bool reference_is_digit(int32_t c, bool hex);
|
|
10
|
+
static inline int hex_digit_value(int32_t c);
|
|
11
|
+
static inline bool is_ascii_letter(int32_t c);
|
|
12
|
+
static inline bool is_ascii_digit(int32_t c);
|
|
13
|
+
static inline bool reference_is_digit(int32_t c, bool hex);
|
|
14
|
+
static inline bool lexer_eof(const TSLexer *lexer);
|
|
14
15
|
|
|
15
16
|
static bool scan_template_chars(TSLexer *lexer, TSSymbol symbol) {
|
|
16
17
|
lexer->result_symbol = symbol;
|
|
17
18
|
for (bool has_content = false;; has_content = true) {
|
|
18
|
-
|
|
19
|
-
if (lexer->eof(lexer)) return false;
|
|
19
|
+
if (lexer_eof(lexer)) return false;
|
|
20
20
|
switch (lexer->lookahead) {
|
|
21
21
|
case '`':
|
|
22
22
|
case '\\':
|
|
23
|
+
if (has_content) lexer->mark_end(lexer);
|
|
23
24
|
return has_content;
|
|
24
25
|
case '$':
|
|
26
|
+
if (has_content) lexer->mark_end(lexer);
|
|
25
27
|
lexer->advance(lexer, false);
|
|
26
28
|
if (lexer->lookahead == '{') return has_content;
|
|
27
29
|
break;
|
|
@@ -35,24 +37,20 @@ static bool scan_jsx_text(TSLexer *lexer, TSSymbol symbol) {
|
|
|
35
37
|
bool saw_text = false;
|
|
36
38
|
bool at_newline = false;
|
|
37
39
|
lexer->result_symbol = symbol;
|
|
38
|
-
|
|
39
|
-
lexer->
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
at_newline = false;
|
|
48
|
-
continue;
|
|
49
|
-
default:
|
|
50
|
-
break;
|
|
40
|
+
while (!lexer_eof(lexer)) {
|
|
41
|
+
int32_t c = lexer->lookahead;
|
|
42
|
+
if (c == '<' || c == '>' || c == '{' || c == '}') break;
|
|
43
|
+
if (c == '&') {
|
|
44
|
+
lexer->mark_end(lexer);
|
|
45
|
+
if (scan_character_reference(lexer)) return saw_text;
|
|
46
|
+
saw_text = true;
|
|
47
|
+
at_newline = false;
|
|
48
|
+
continue;
|
|
51
49
|
}
|
|
52
50
|
// Use ASCII classes here because Babel retains Unicode spaces in JSX text.
|
|
53
|
-
bool is_space = (
|
|
51
|
+
bool is_space = (uint32_t)(c - '\t') <= '\r' - '\t' || c == ' ';
|
|
54
52
|
// Babel splits JSX text into lines at CR/LF; U+2028 and U+2029 stay text.
|
|
55
|
-
if (
|
|
53
|
+
if (c == '\n' || c == '\r') {
|
|
56
54
|
at_newline = true;
|
|
57
55
|
} else {
|
|
58
56
|
at_newline &= is_space;
|
|
@@ -60,6 +58,8 @@ static bool scan_jsx_text(TSLexer *lexer, TSSymbol symbol) {
|
|
|
60
58
|
}
|
|
61
59
|
lexer->advance(lexer, false);
|
|
62
60
|
}
|
|
61
|
+
if (saw_text) lexer->mark_end(lexer);
|
|
62
|
+
return saw_text;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
static bool scan_character_reference(TSLexer *lexer) {
|
|
@@ -85,7 +85,7 @@ static bool scan_character_reference(TSLexer *lexer) {
|
|
|
85
85
|
|
|
86
86
|
static bool scan_template_escape(TSLexer *lexer, TSSymbol symbol) {
|
|
87
87
|
lexer->advance(lexer, false);
|
|
88
|
-
if (
|
|
88
|
+
if (lexer_eof(lexer) || !scan_template_escape_value(lexer)) return false;
|
|
89
89
|
lexer->mark_end(lexer);
|
|
90
90
|
lexer->result_symbol = symbol;
|
|
91
91
|
return true;
|
|
@@ -133,23 +133,27 @@ static bool scan_template_code_point(TSLexer *lexer) {
|
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
static int hex_digit_value(int32_t c) {
|
|
136
|
+
static inline int hex_digit_value(int32_t c) {
|
|
137
137
|
if (is_ascii_digit(c)) return c - '0';
|
|
138
138
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
139
139
|
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
|
140
140
|
return -1;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
static bool is_ascii_letter(int32_t c) {
|
|
144
|
-
return (c
|
|
143
|
+
static inline bool is_ascii_letter(int32_t c) {
|
|
144
|
+
return (uint32_t)((c | 0x20) - 'a') <= 'z' - 'a';
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
static bool reference_is_digit(int32_t c, bool hex) {
|
|
147
|
+
static inline bool reference_is_digit(int32_t c, bool hex) {
|
|
148
148
|
return hex ? hex_digit_value(c) >= 0 : is_ascii_digit(c);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
static bool is_ascii_digit(int32_t c) {
|
|
152
|
-
return c
|
|
151
|
+
static inline bool is_ascii_digit(int32_t c) {
|
|
152
|
+
return (uint32_t)(c - '0') <= 9;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static inline bool lexer_eof(const TSLexer *lexer) {
|
|
156
|
+
return lexer->lookahead == 0 && lexer->eof(lexer);
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
#endif
|
|
Binary file
|
|
Binary file
|