@willbooster/tree-sitter-javascript 2.0.2 → 3.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 +5 -6
- package/grammar.js +127 -11
- package/package.json +3 -3
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +1 -1
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.2.2 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,13 @@ 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)
|
|
66
|
-
|
|
67
|
-
malformed input):
|
|
65
|
+
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) 1.2.2 or newer. The canonical constructor
|
|
66
|
+
supertype query requires this runtime version. This is the runtime this package is tested and fuzzed with:
|
|
68
67
|
|
|
69
68
|
```toml
|
|
70
69
|
[dependencies]
|
|
71
|
-
tree-sitter = { package = "willbooster-tree-sitter", version = "1" }
|
|
72
|
-
tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "
|
|
70
|
+
tree-sitter = { package = "willbooster-tree-sitter", version = "1.2.2" }
|
|
71
|
+
tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "3" }
|
|
73
72
|
```
|
|
74
73
|
|
|
75
74
|
```rust
|
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: ($) => [
|
|
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(
|
|
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
|
+
),
|
|
874
961
|
|
|
875
|
-
|
|
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
|
+
),
|
|
981
|
+
|
|
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(
|
|
@@ -881,9 +992,14 @@ module.exports = grammar({
|
|
|
881
992
|
'unary_void',
|
|
882
993
|
seq(
|
|
883
994
|
alias($._await_keyword, 'await'),
|
|
884
|
-
optional
|
|
885
|
-
optional(
|
|
886
|
-
|
|
995
|
+
// Independent optional prefixes duplicate parser states; the yield start/context pair stays one alternative.
|
|
996
|
+
optional(
|
|
997
|
+
choice(
|
|
998
|
+
$._await_identifier_line_break,
|
|
999
|
+
seq($._await_yield_identifier_start, optional($._await_yield_identifier_context)),
|
|
1000
|
+
$._line_break_after_await
|
|
1001
|
+
)
|
|
1002
|
+
),
|
|
887
1003
|
$.expression,
|
|
888
1004
|
$._await_operand_end
|
|
889
1005
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-javascript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "JavaScript grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
47
47
|
"@willbooster/oxlint-config": "1.4.8",
|
|
48
48
|
"@willbooster/wb": "22.13.1",
|
|
49
|
-
"@willbooster/web-tree-sitter": "1.
|
|
49
|
+
"@willbooster/web-tree-sitter": "1.2.2",
|
|
50
50
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
51
51
|
"lefthook": "2.1.14",
|
|
52
52
|
"oxfmt": "0.70.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"wrangler": "4.136.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@willbooster/web-tree-sitter": "^1.
|
|
65
|
+
"@willbooster/web-tree-sitter": "^1.2.2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"@willbooster/web-tree-sitter": {
|
|
Binary file
|