@willbooster/tree-sitter-javascript 7.0.1 → 7.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 +15 -6
- package/grammar.js +12 -4
- package/grammars/script/grammar.js +6 -0
- package/grammars/script/src/node-types.json +3616 -0
- package/package.json +3 -1
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter-javascript_script.wasm +0 -0
- package/tree-sitter.json +23 -2
package/README.md
CHANGED
|
@@ -17,11 +17,16 @@ This fork fixes parsing bugs and raises conformance with [ECMAScript (ECMA-262)]
|
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
|
-
The npm package ships
|
|
20
|
+
The npm package ships two languages for
|
|
21
21
|
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
|
|
22
22
|
browsers, and Cloudflare Workers. The parser carries the ABI number of WillBooster/tree-sitter (`0x57420006`), so it
|
|
23
23
|
loads only with that runtime, version 7.0.5 or newer within major 7; the upstream runtime rejects it. In Node.js and Bun, load it from
|
|
24
|
-
the package
|
|
24
|
+
the package. Choose `tree-sitter-javascript.wasm` for the Module goal, or
|
|
25
|
+
`tree-sitter-javascript_script.wasm` for the Script goal. The source goal comes from the host or file type;
|
|
26
|
+
`.mjs` uses Module and `.cjs` uses Script, while `.js` depends on the host. For example, `await\nvalue` is one
|
|
27
|
+
await expression in a Module and two identifier statements in a Script. Both languages preserve the same node
|
|
28
|
+
schema and query names. As with other tree-sitter grammars, parsing does not enforce every ECMAScript early error.
|
|
29
|
+
For the native CLI, select Script with `tree-sitter parse --grammar-path grammars/script`.
|
|
25
30
|
|
|
26
31
|
```js
|
|
27
32
|
import { fileURLToPath } from 'node:url';
|
|
@@ -34,7 +39,9 @@ parser.setLanguage(await Language.load(wasmPath));
|
|
|
34
39
|
const tree = parser.parse('const App = () => <p>Hello</p>;\n');
|
|
35
40
|
```
|
|
36
41
|
|
|
37
|
-
In browsers, let your bundler serve
|
|
42
|
+
In browsers, let your bundler serve the runtime and the selected language `.wasm` files, then pass their URLs.
|
|
43
|
+
For the Script goal, replace the language import below with
|
|
44
|
+
`@willbooster/tree-sitter-javascript/tree-sitter-javascript_script.wasm?url`:
|
|
38
45
|
|
|
39
46
|
```js
|
|
40
47
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
@@ -46,8 +53,9 @@ const parser = new Parser();
|
|
|
46
53
|
parser.setLanguage(await Language.load(javascriptUrl));
|
|
47
54
|
```
|
|
48
55
|
|
|
49
|
-
In Cloudflare Workers, which do not allow compiling Wasm at run time, import
|
|
50
|
-
without Node.js compatibility
|
|
56
|
+
In Cloudflare Workers, which do not allow compiling Wasm at run time, import the runtime and the selected language
|
|
57
|
+
`.wasm` files as modules, with or without Node.js compatibility. For the Script goal, replace the language import
|
|
58
|
+
below with `@willbooster/tree-sitter-javascript/tree-sitter-javascript_script.wasm`:
|
|
51
59
|
|
|
52
60
|
```js
|
|
53
61
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
@@ -75,6 +83,7 @@ tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", versi
|
|
|
75
83
|
```rust
|
|
76
84
|
let mut parser = tree_sitter::Parser::new();
|
|
77
85
|
parser.set_language(&tree_sitter_javascript::LANGUAGE.into())?;
|
|
86
|
+
// Use LANGUAGE_SCRIPT for the Script goal.
|
|
78
87
|
```
|
|
79
88
|
|
|
80
89
|
## Development
|
|
@@ -96,7 +105,7 @@ the download fails or the release has no binary that runs here.
|
|
|
96
105
|
`bun run generate` records a fresh generation profile from the applicable `test/corpus` cases and Git-tracked
|
|
97
106
|
files in `examples/`, then generates compact parser tables. The parser also embeds metadata from `tree-sitter.json`. After changing a grammar,
|
|
98
107
|
`tree-sitter.json`, a corpus case, or a tracked example,
|
|
99
|
-
regenerate and commit `src
|
|
108
|
+
regenerate and commit the affected grammar's `src/` directory. Stage added or removed examples with `git add -A examples` before generation so the profile uses the intended file list.
|
|
100
109
|
Profiles in `.tmp/generation-profiles/` are temporary and must not be committed. `bun run build-wasm`, `bun run build/ci`,
|
|
101
110
|
and the release build regenerate the parsers before compiling them.
|
|
102
111
|
|
package/grammar.js
CHANGED
|
@@ -1455,28 +1455,36 @@ module.exports = grammar({
|
|
|
1455
1455
|
seq(
|
|
1456
1456
|
optional('static'),
|
|
1457
1457
|
choice(
|
|
1458
|
-
seq(
|
|
1458
|
+
seq(
|
|
1459
|
+
field('property', $._field_name),
|
|
1460
|
+
optional(choice($._field_initializer, sym('_line_break_after_field')))
|
|
1461
|
+
),
|
|
1459
1462
|
// A line break after `get` or `set` continues a getter or setter. Allowing both sentinels here tells
|
|
1460
1463
|
// the scanner that a `*` on the next line cannot continue the member, unlike after `static`.
|
|
1461
1464
|
seq(
|
|
1462
1465
|
field('property', alias(choice('get', 'set'), sym('property_identifier'))),
|
|
1463
|
-
optional(
|
|
1466
|
+
optional(
|
|
1467
|
+
choice($._field_initializer, sym('_line_break_after_modifier'), sym('_line_break_after_field'))
|
|
1468
|
+
)
|
|
1464
1469
|
)
|
|
1465
1470
|
)
|
|
1466
1471
|
),
|
|
1467
1472
|
// A line break after a leading `static` continues a static member; after `static static`, it ends the field.
|
|
1468
1473
|
seq(
|
|
1469
1474
|
field('property', alias('static', sym('property_identifier'))),
|
|
1470
|
-
optional(choice($.
|
|
1475
|
+
optional(choice($._field_initializer, sym('_line_break_after_modifier')))
|
|
1471
1476
|
),
|
|
1472
1477
|
seq(
|
|
1473
1478
|
'static',
|
|
1474
1479
|
field('property', alias('static', sym('property_identifier'))),
|
|
1475
|
-
optional(choice($.
|
|
1480
|
+
optional(choice($._field_initializer, sym('_line_break_after_field')))
|
|
1476
1481
|
)
|
|
1477
1482
|
)
|
|
1478
1483
|
),
|
|
1479
1484
|
|
|
1485
|
+
_field_initializer: ($) =>
|
|
1486
|
+
seq('=', sym('_sync_function_start'), field('value', $.expression), sym('_arrow_context_end')),
|
|
1487
|
+
|
|
1480
1488
|
formal_parameters: ($) => seq('(', optional(seq(commaSep1($._formal_parameter), optional(','))), ')'),
|
|
1481
1489
|
|
|
1482
1490
|
class_static_block: ($) => seq('static', field('body', alias($._class_member_body, $.statement_block))),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const { grammar } = /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
|
|
4
|
+
|
|
5
|
+
// oxlint-disable-next-line unicorn/prefer-module -- The CLI loads grammar extensions as CommonJS.
|
|
6
|
+
module.exports = grammar(require('../../grammar.js'), { name: 'javascript_script', rules: {} });
|