@willbooster/tree-sitter-javascript 0.0.0-placeholder.0 → 1.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Max Brunsfeld
4
+ Copyright (c) 2026 WillBooster Inc.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,109 @@
1
1
  # @willbooster/tree-sitter-javascript
2
2
 
3
- This version is a placeholder that reserves the package name so that releases can be published from GitHub Actions with trusted publishing. Use 1.0.0 or later.
3
+ [![npm version](https://img.shields.io/npm/v/@willbooster/tree-sitter-javascript.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-javascript)
4
+ [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-javascript.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-javascript)
5
+ [![Test](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test.yml)
6
+ [![Test rust](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test-rust.yml)
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.26.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
+ [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-javascript.svg)](https://crates.io/crates/willbooster-tree-sitter-javascript)
10
+
11
+ JavaScript and JSX grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
12
+ [tree-sitter/tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript). We are grateful
13
+ to its authors and contributors. This is not an official release of that project.
14
+
15
+ This fork fixes parsing bugs and raises conformance with [ECMAScript (ECMA-262)](https://tc39.es/ecma262/) and [JSX](https://facebook.github.io/jsx/).
16
+
17
+ ## Usage
18
+
19
+ The npm package ships `tree-sitter-javascript.wasm` for
20
+ [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
21
+ browsers, and Cloudflare Workers. In Node.js and Bun, load it from the package:
22
+
23
+ ```js
24
+ import { fileURLToPath } from 'node:url';
25
+ import { Language, Parser } from '@willbooster/web-tree-sitter';
26
+
27
+ await Parser.init();
28
+ const parser = new Parser();
29
+ const wasmPath = fileURLToPath(import.meta.resolve('@willbooster/tree-sitter-javascript/tree-sitter-javascript.wasm'));
30
+ parser.setLanguage(await Language.load(wasmPath));
31
+ const tree = parser.parse('const App = () => <p>Hello</p>;\n');
32
+ ```
33
+
34
+ In browsers, let your bundler serve both `.wasm` files and pass their URLs:
35
+
36
+ ```js
37
+ import { Language, Parser } from '@willbooster/web-tree-sitter';
38
+ import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url'; // Vite
39
+ import javascriptUrl from '@willbooster/tree-sitter-javascript/tree-sitter-javascript.wasm?url';
40
+
41
+ await Parser.init({ locateFile: () => runtimeUrl });
42
+ const parser = new Parser();
43
+ parser.setLanguage(await Language.load(javascriptUrl));
44
+ ```
45
+
46
+ In Cloudflare Workers, which do not allow compiling Wasm at run time, import both `.wasm` files as modules, with or
47
+ without Node.js compatibility:
48
+
49
+ ```js
50
+ import { Language, Parser } from '@willbooster/web-tree-sitter';
51
+ import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
52
+ import javascript from '@willbooster/tree-sitter-javascript/tree-sitter-javascript.wasm';
53
+
54
+ await Parser.init({ wasmModule: runtime });
55
+ const parser = new Parser();
56
+ parser.setLanguage(await Language.load(javascript));
57
+ ```
58
+
59
+ The package also ships the node types in `src/node-types.json`, and `grammar.js` and the queries in `queries/` for
60
+ grammars that extend this one (e.g. `require('@willbooster/tree-sitter-javascript/grammar')`).
61
+
62
+ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-javascript):
63
+
64
+ ```toml
65
+ [dependencies]
66
+ tree-sitter = "0.27"
67
+ tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "1" }
68
+ ```
69
+
70
+ ```rust
71
+ let mut parser = tree_sitter::Parser::new();
72
+ parser.set_language(&tree_sitter_javascript::LANGUAGE.into())?;
73
+ ```
74
+
75
+ ## Development
76
+
77
+ ```sh
78
+ mise install
79
+ bun install --frozen-lockfile
80
+ bun run build/ci
81
+ bun run test
82
+ script/parse-examples
83
+ cargo test
84
+ ```
85
+
86
+ `bun run test` runs:
87
+
88
+ - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
89
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
90
+ reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
91
+ `TREE_SITTER_EDITS` run other or more edits;
92
+ - a check that the real-world JavaScript files in `examples/`, the checked-in ones and those of the cloned repository,
93
+ fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repository. The example repository is pinned to a commit in
94
+ `script/parse-examples`. After a grammar change or a moved pin alters that list, `script/parse-examples` rewrites
95
+ it; review its diff before committing;
96
+ - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
97
+ linear time, since consumers parse files while they are being edited. It loads the Wasm build through
98
+ @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parser;
99
+ - checks that the Wasm build parses in Chromium (`test/unit/browser/`) and in Cloudflare Workers with and without
100
+ Node.js compatibility (`test/unit/workers.test.ts`). Run `bun run test/ci-setup` once before the first
101
+ run to install Chromium and, on Linux, the system libraries it needs.
102
+
103
+ CI also runs these tests on Linux arm64 and macOS, where the Rust binding compiles the parser natively, and fuzzes the parser with libFuzzer and sanitizers
104
+ (`.github/workflows/robustness.yml`).
105
+
106
+ ### References
107
+
108
+ - [The ESTree Spec](https://github.com/estree/estree)
109
+ - [The ECMAScript 2025 Spec](https://tc39.es/ecma262/2025/)