@willbooster/tree-sitter-javascript 2.0.3 → 4.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
@@ -19,7 +19,7 @@ This fork fixes parsing bugs and raises conformance with [ECMAScript (ECMA-262)]
19
19
 
20
20
  The npm package ships `tree-sitter-javascript.wasm` for
21
21
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
22
- browsers, and Cloudflare Workers. In Node.js and Bun, load it from the package:
22
+ browsers, and Cloudflare Workers. Use runtime 1.3.0 or newer. In Node.js and Bun, load it from the package:
23
23
 
24
24
  ```js
25
25
  import { fileURLToPath } from 'node:url';
@@ -62,14 +62,12 @@ The package also ships the node types in `src/node-types.json`, the highlight, i
62
62
  `require('@willbooster/tree-sitter-javascript/grammar')`). The crate ships `tree-sitter.json` and `queries/` too.
63
63
 
64
64
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-javascript) and on
65
- [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
66
- fuzzed with (the grammar also loads in the upstream `tree-sitter` crate 0.27, whose error recovery never ends on some
67
- malformed input):
65
+ [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) 1.3.0 or newer for the compact ABI 16 parser:
68
66
 
69
67
  ```toml
70
68
  [dependencies]
71
- tree-sitter = { package = "willbooster-tree-sitter", version = "1" }
72
- tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "1" }
69
+ tree-sitter = { package = "willbooster-tree-sitter", version = "1.3.0" }
70
+ tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "4" }
73
71
  ```
74
72
 
75
73
  ```rust
@@ -93,6 +91,13 @@ locked in `Cargo.lock` (`script/tree-sitter`), whose generator and runtime have
93
91
  `script/fork-cli` downloads that CLI into `.tmp/` from its GitHub Release on first use, or builds it with `cargo` when
94
92
  the download fails or the release has no binary that runs here.
95
93
 
94
+ `bun run generate` records a fresh ABI 16 generation profile from the applicable `test/corpus` cases and Git-tracked
95
+ files in `examples/`, then generates compact parser tables. The parser also embeds metadata from `tree-sitter.json`. After changing a grammar,
96
+ `tree-sitter.json`, a corpus case, or a tracked example,
97
+ regenerate and commit `src/`. Stage added or removed examples with `git add -A examples` before generation so the profile uses the intended file list.
98
+ Profiles in `.tmp/generation-profiles/` are temporary and must not be committed. `bun run build-wasm`, `bun run build/ci`,
99
+ and the release build regenerate the parsers before compiling them.
100
+
96
101
  `bun run test` runs:
97
102
 
98
103
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
package/grammar.js CHANGED
@@ -107,6 +107,8 @@ module.exports = grammar({
107
107
  $._export_default,
108
108
  $._default_declaration_start,
109
109
  $._regex_flags_start,
110
+ $._argumentless_new_end,
111
+ $._constructor_async_function_start,
110
112
  ],
111
113
 
112
114
  extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -116,7 +118,15 @@ module.exports = grammar({
116
118
  properties: () => [],
117
119
  },
118
120
 
119
- supertypes: ($) => [$.statement, $.declaration, $.expression, $.primary_expression, $.pattern],
121
+ supertypes: ($) => [
122
+ $.statement,
123
+ $.declaration,
124
+ $.expression,
125
+ $.primary_expression,
126
+ $.pattern,
127
+ $._constructor,
128
+ $._constructor_chain_base,
129
+ ],
120
130
 
121
131
  inline: ($) => [
122
132
  $._call_signature,
@@ -864,15 +874,116 @@ module.exports = grammar({
864
874
  )
865
875
  ),
866
876
 
867
- // As in ECMAScript, a member access or index extends the nearest `new` with arguments, while an argument list fills
868
- // the nearest `new` that still lacks one: `new new A().b` constructs `new A().b`, `new new A().b(2)` constructs
869
- // `new A().b` with `2`, and `new new A()(2)` constructs `new A()`. The 'member' and 'new' precedences make the parser
870
- // shift a `.`, `[`, or argument list after a constructor rather than end a `new` without arguments, so that form
871
- // never takes one. Both forms are primary expressions, so a nested `new` matches the constructor field's type.
872
877
  new_expression: ($) =>
873
- prec('new', seq('new', field('constructor', $.primary_expression), field('arguments', $.arguments))),
878
+ prec(
879
+ 'new',
880
+ seq('new', field('constructor', alias($._constructor, $.primary_expression)), field('arguments', $.arguments))
881
+ ),
882
+
883
+ _constructor_function_expression: ($) =>
884
+ prec(
885
+ 'literal',
886
+ seq(
887
+ optional($._constructor_async_function_start),
888
+ optional('async'),
889
+ 'function',
890
+ field('name', optional($.identifier)),
891
+ $._call_signature,
892
+ field('body', $.statement_block)
893
+ )
894
+ ),
895
+
896
+ _constructor_generator_function: ($) =>
897
+ prec(
898
+ 'literal',
899
+ seq(
900
+ optional($._constructor_async_function_start),
901
+ optional('async'),
902
+ 'function',
903
+ '*',
904
+ field('name', optional($.identifier)),
905
+ $._call_signature,
906
+ field('body', $.statement_block)
907
+ )
908
+ ),
909
+
910
+ _constructor_atom: ($) =>
911
+ choice(
912
+ $._jsx_element,
913
+ $.parenthesized_expression,
914
+ $._identifier,
915
+ alias($._await_yield_identifier, $.identifier),
916
+ alias($._reserved_identifier, $.identifier),
917
+ $.this,
918
+ $.super,
919
+ $.number,
920
+ $.string,
921
+ $.template_string,
922
+ $.regex,
923
+ $.true,
924
+ $.false,
925
+ $.null,
926
+ $.object,
927
+ $.array,
928
+ alias($._constructor_function_expression, $.function_expression),
929
+ alias($._constructor_generator_function, $.generator_function),
930
+ $.class,
931
+ $.meta_property
932
+ ),
933
+
934
+ _constructor: ($) =>
935
+ choice(
936
+ $._constructor_atom,
937
+ $.new_expression,
938
+ alias($._argumentless_new_expression, $.new_expression),
939
+ alias($._constructor_member, $.member_expression),
940
+ alias($._constructor_subscript, $.subscript_expression),
941
+ alias($._constructor_tag, $.call_expression)
942
+ ),
943
+
944
+ _constructor_chain_base: ($) =>
945
+ choice(alias($._constructor, $.primary_expression), alias($._constructor_import, $.call_expression)),
946
+
947
+ _constructor_import: ($) => prec('call', seq(field('function', $.import), field('arguments', $.arguments))),
948
+
949
+ _constructor_member: ($) =>
950
+ prec(
951
+ 'member',
952
+ seq(
953
+ field('object', alias($._constructor_chain_base, $.primary_expression)),
954
+ '.',
955
+ field(
956
+ 'property',
957
+ choice($.private_property_identifier, reserved('properties', alias($.identifier, $.property_identifier)))
958
+ )
959
+ )
960
+ ),
961
+
962
+ _constructor_subscript: ($) =>
963
+ prec.right(
964
+ 'member',
965
+ seq(
966
+ field('object', alias($._constructor_chain_base, $.primary_expression)),
967
+ '[',
968
+ field('index', $._expressions),
969
+ ']'
970
+ )
971
+ ),
972
+
973
+ _constructor_tag: ($) =>
974
+ prec(
975
+ 'template_call',
976
+ seq(
977
+ field('function', alias($._constructor_chain_base, $.primary_expression)),
978
+ field('arguments', $.template_string)
979
+ )
980
+ ),
874
981
 
875
- _argumentless_new_expression: ($) => prec.right('new', seq('new', field('constructor', $.primary_expression))),
982
+ _argumentless_new_expression: ($) =>
983
+ prec.right(
984
+ 'new',
985
+ seq('new', field('constructor', alias($._constructor, $.primary_expression)), $._argumentless_new_end)
986
+ ),
876
987
 
877
988
  await_expression: ($) =>
878
989
  prec.dynamic(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "2.0.3",
3
+ "version": "4.0.0",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -22,10 +22,11 @@
22
22
  "*.wasm"
23
23
  ],
24
24
  "scripts": {
25
- "build-wasm": "script/tree-sitter build --wasm",
26
- "build/ci": "script/tree-sitter generate && script/tree-sitter build --wasm",
25
+ "build-wasm": "script/generate --build-wasm",
26
+ "build/ci": "bun run build-wasm",
27
27
  "cleanup": "bun wb lint --fix --format",
28
28
  "format": "bun wb lint --format",
29
+ "generate": "script/generate",
29
30
  "lint": "bun wb lint",
30
31
  "lint-fix": "bun wb lint --fix",
31
32
  "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
@@ -46,7 +47,7 @@
46
47
  "@willbooster/oxfmt-config": "1.2.2",
47
48
  "@willbooster/oxlint-config": "1.4.8",
48
49
  "@willbooster/wb": "22.13.1",
49
- "@willbooster/web-tree-sitter": "1.0.16",
50
+ "@willbooster/web-tree-sitter": "1.4.0",
50
51
  "conventional-changelog-conventionalcommits": "10.4.0",
51
52
  "lefthook": "2.1.14",
52
53
  "oxfmt": "0.70.0",
@@ -62,7 +63,7 @@
62
63
  "wrangler": "4.136.2"
63
64
  },
64
65
  "peerDependencies": {
65
- "@willbooster/web-tree-sitter": "^1.0.0"
66
+ "@willbooster/web-tree-sitter": "^1.3.0"
66
67
  },
67
68
  "peerDependenciesMeta": {
68
69
  "@willbooster/web-tree-sitter": {
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "2.0.3",
27
+ "version": "4.0.0",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [