@willbooster/tree-sitter-javascript 22.0.2 → 24.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 +3 -3
- package/grammar.js +4 -7
- package/grammars/script/src/node-types.json +1 -1
- package/package.json +3 -3
- package/src/literal.h +32 -28
- package/src/node-types.json +1 -1
- 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
|
@@ -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 19.1.1, and its optional peer dependency requires 19.1.1 or later within 19.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 19.1.1:
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
|
-
cargo add willbooster-tree-sitter@
|
|
87
|
+
cargo add willbooster-tree-sitter@19.1.1 --rename tree-sitter
|
|
88
88
|
cargo add willbooster-tree-sitter-javascript --rename tree-sitter-javascript
|
|
89
89
|
```
|
|
90
90
|
|
package/grammar.js
CHANGED
|
@@ -1608,14 +1608,11 @@ module.exports = grammar({
|
|
|
1608
1608
|
seq(
|
|
1609
1609
|
optional('static'),
|
|
1610
1610
|
choice(
|
|
1611
|
-
seq(
|
|
1612
|
-
field('property', $._field_name),
|
|
1613
|
-
optional(choice($._field_initializer, sym('_line_break_after_field')))
|
|
1614
|
-
),
|
|
1611
|
+
seq(field('name', $._field_name), optional(choice($._field_initializer, sym('_line_break_after_field')))),
|
|
1615
1612
|
// A line break after `get` or `set` continues a getter or setter. Allowing both sentinels here tells
|
|
1616
1613
|
// the scanner that a `*` on the next line cannot continue the member, unlike after `static`.
|
|
1617
1614
|
seq(
|
|
1618
|
-
field('
|
|
1615
|
+
field('name', alias(choice('get', 'set'), sym('property_identifier'))),
|
|
1619
1616
|
optional(
|
|
1620
1617
|
choice($._field_initializer, sym('_line_break_after_modifier'), sym('_line_break_after_field'))
|
|
1621
1618
|
)
|
|
@@ -1624,12 +1621,12 @@ module.exports = grammar({
|
|
|
1624
1621
|
),
|
|
1625
1622
|
// A line break after a leading `static` continues a static member; after `static static`, it ends the field.
|
|
1626
1623
|
seq(
|
|
1627
|
-
field('
|
|
1624
|
+
field('name', alias('static', sym('property_identifier'))),
|
|
1628
1625
|
optional(choice($._field_initializer, sym('_line_break_after_modifier')))
|
|
1629
1626
|
),
|
|
1630
1627
|
seq(
|
|
1631
1628
|
'static',
|
|
1632
|
-
field('
|
|
1629
|
+
field('name', alias('static', sym('property_identifier'))),
|
|
1633
1630
|
optional(choice($._field_initializer, sym('_line_break_after_field')))
|
|
1634
1631
|
)
|
|
1635
1632
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-javascript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.0.0",
|
|
4
4
|
"description": "JavaScript grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@vitest/browser-playwright": "5.0.5",
|
|
54
54
|
"@willbooster/oxlint-config": "1.4.9",
|
|
55
55
|
"@willbooster/wb": "23.3.0",
|
|
56
|
-
"@willbooster/web-tree-sitter": "
|
|
56
|
+
"@willbooster/web-tree-sitter": "19.1.1",
|
|
57
57
|
"acorn": "8.19.0",
|
|
58
58
|
"acorn-jsx": "5.3.2",
|
|
59
59
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"wrangler": "4.156.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@willbooster/web-tree-sitter": "^
|
|
70
|
+
"@willbooster/web-tree-sitter": "^19.1.1"
|
|
71
71
|
},
|
|
72
72
|
"peerDependenciesMeta": {
|
|
73
73
|
"@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
|
package/src/node-types.json
CHANGED
|
Binary file
|
|
Binary file
|