@willbooster/tree-sitter-javascript 23.0.0 → 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 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 19.1.0, and its optional peer dependency requires 19.1.0 or later within 19.x. In Node.js and Bun, load it from
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 19.1.0:
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@19.1.0 --rename 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "23.0.0",
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": "19.1.0",
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": "^19.1.0"
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
- lexer->mark_end(lexer);
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
- for (;;) {
39
- lexer->mark_end(lexer);
40
- if (lexer->eof(lexer)) return saw_text;
41
- switch (lexer->lookahead) {
42
- case '<': case '>': case '{': case '}':
43
- return saw_text;
44
- case '&':
45
- if (scan_character_reference(lexer)) return saw_text;
46
- saw_text = true;
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 = (lexer->lookahead >= '\t' && lexer->lookahead <= '\r') || lexer->lookahead == ' ';
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 (lexer->lookahead == '\n' || lexer->lookahead == '\r') {
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 (lexer->eof(lexer) || !scan_template_escape_value(lexer)) return false;
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 >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
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 >= '0' && c <= '9';
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
package/tree-sitter.json CHANGED
@@ -34,7 +34,7 @@
34
34
  }
35
35
  ],
36
36
  "metadata": {
37
- "version": "23.0.0",
37
+ "version": "24.0.0",
38
38
  "license": "MIT",
39
39
  "description": "JavaScript grammar for tree-sitter",
40
40
  "authors": [