@willbooster/tree-sitter-javascript 5.0.3 → 6.0.1
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 +1 -1
- package/grammar.js +136 -79
- package/package.json +2 -3
- package/src/node-types.json +0 -10
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-javascript/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-javascript)
|
|
10
10
|
|
|
11
11
|
JavaScript and JSX grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
package/grammar.js
CHANGED
|
@@ -113,6 +113,11 @@ module.exports = grammar({
|
|
|
113
113
|
sym('_regex_flags_start'),
|
|
114
114
|
sym('_argumentless_new_end'),
|
|
115
115
|
sym('_constructor_async_function_start'),
|
|
116
|
+
sym('_sync_function_start'),
|
|
117
|
+
sym('_async_function_start'),
|
|
118
|
+
sym('_function_context_end'),
|
|
119
|
+
sym('_arrow_context_end'),
|
|
120
|
+
sym('_await_identifier'),
|
|
116
121
|
],
|
|
117
122
|
|
|
118
123
|
extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
|
|
@@ -126,6 +131,7 @@ module.exports = grammar({
|
|
|
126
131
|
supertypes: ($) => [
|
|
127
132
|
$.statement,
|
|
128
133
|
$.declaration,
|
|
134
|
+
$._decorated_export_declaration,
|
|
129
135
|
$.expression,
|
|
130
136
|
$.primary_expression,
|
|
131
137
|
$.pattern,
|
|
@@ -223,6 +229,7 @@ module.exports = grammar({
|
|
|
223
229
|
|
|
224
230
|
export_statement: ($) =>
|
|
225
231
|
choice(
|
|
232
|
+
field('declaration', alias($._decorated_export_declaration, $.declaration)),
|
|
226
233
|
seq(
|
|
227
234
|
'export',
|
|
228
235
|
choice(
|
|
@@ -236,7 +243,6 @@ module.exports = grammar({
|
|
|
236
243
|
$._semicolon
|
|
237
244
|
),
|
|
238
245
|
seq(
|
|
239
|
-
repeat(field('decorator', $.decorator)),
|
|
240
246
|
'export',
|
|
241
247
|
choice(
|
|
242
248
|
field('declaration', $.declaration),
|
|
@@ -246,6 +252,23 @@ module.exports = grammar({
|
|
|
246
252
|
)
|
|
247
253
|
),
|
|
248
254
|
|
|
255
|
+
_decorated_export_declaration: ($) => alias($._decorated_export_class, $.class_declaration),
|
|
256
|
+
|
|
257
|
+
_decorated_export_class: ($) =>
|
|
258
|
+
prec(
|
|
259
|
+
'declaration',
|
|
260
|
+
seq(
|
|
261
|
+
repeat1(field('decorator', $.decorator)),
|
|
262
|
+
'export',
|
|
263
|
+
choice(
|
|
264
|
+
seq('class', field('name', $.identifier)),
|
|
265
|
+
seq('default', 'class', field('name', optional($.identifier)))
|
|
266
|
+
),
|
|
267
|
+
optional($.class_heritage),
|
|
268
|
+
field('body', $.class_body)
|
|
269
|
+
)
|
|
270
|
+
),
|
|
271
|
+
|
|
249
272
|
namespace_export: ($) => seq('*', 'as', $._module_export_name),
|
|
250
273
|
|
|
251
274
|
export_clause: ($) => seq('{', commaSep($.export_specifier), optional(','), '}'),
|
|
@@ -812,85 +835,97 @@ module.exports = grammar({
|
|
|
812
835
|
function_expression: ($) =>
|
|
813
836
|
prec(
|
|
814
837
|
'literal',
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
838
|
+
functionContext((async) =>
|
|
839
|
+
seq(
|
|
840
|
+
...(async ? ['async'] : []),
|
|
841
|
+
'function',
|
|
842
|
+
field('name', optional($.identifier)),
|
|
843
|
+
$._call_signature,
|
|
844
|
+
contextBody(async, field('body', $.statement_block))
|
|
845
|
+
)
|
|
821
846
|
)
|
|
822
847
|
),
|
|
823
848
|
|
|
824
849
|
function_declaration: ($) =>
|
|
825
850
|
prec.right(
|
|
826
851
|
'declaration',
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
852
|
+
functionContext((async) =>
|
|
853
|
+
seq(
|
|
854
|
+
choice(
|
|
855
|
+
seq(
|
|
856
|
+
sym('_default_declaration_start'),
|
|
857
|
+
...(async ? ['async'] : []),
|
|
858
|
+
'function',
|
|
859
|
+
field('name', optional($.identifier))
|
|
860
|
+
),
|
|
861
|
+
seq(...(async ? ['async'] : []), 'function', field('name', $.identifier))
|
|
834
862
|
),
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
field('body', $.statement_block)
|
|
863
|
+
$._call_signature,
|
|
864
|
+
contextBody(async, field('body', $.statement_block))
|
|
865
|
+
)
|
|
839
866
|
)
|
|
840
867
|
),
|
|
841
868
|
|
|
842
869
|
generator_function: ($) =>
|
|
843
870
|
prec(
|
|
844
871
|
'literal',
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
872
|
+
functionContext((async) =>
|
|
873
|
+
seq(
|
|
874
|
+
...(async ? ['async'] : []),
|
|
875
|
+
'function',
|
|
876
|
+
'*',
|
|
877
|
+
field('name', optional($.identifier)),
|
|
878
|
+
$._call_signature,
|
|
879
|
+
contextBody(async, field('body', $.statement_block))
|
|
880
|
+
)
|
|
852
881
|
)
|
|
853
882
|
),
|
|
854
883
|
|
|
855
884
|
generator_function_declaration: ($) =>
|
|
856
885
|
prec.right(
|
|
857
886
|
'declaration',
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
887
|
+
functionContext((async) =>
|
|
888
|
+
seq(
|
|
889
|
+
choice(
|
|
890
|
+
seq(
|
|
891
|
+
sym('_default_declaration_start'),
|
|
892
|
+
...(async ? ['async'] : []),
|
|
893
|
+
'function',
|
|
894
|
+
'*',
|
|
895
|
+
field('name', optional($.identifier))
|
|
896
|
+
),
|
|
897
|
+
seq(...(async ? ['async'] : []), 'function', '*', field('name', $.identifier))
|
|
866
898
|
),
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
field('body', $.statement_block)
|
|
899
|
+
$._call_signature,
|
|
900
|
+
contextBody(async, field('body', $.statement_block))
|
|
901
|
+
)
|
|
871
902
|
)
|
|
872
903
|
),
|
|
873
904
|
|
|
874
905
|
arrow_function: ($) =>
|
|
875
906
|
prec.right(
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
907
|
+
functionContext((async) =>
|
|
908
|
+
seq(
|
|
909
|
+
...(async ? ['async'] : []),
|
|
910
|
+
choice(
|
|
911
|
+
field(
|
|
912
|
+
'parameter',
|
|
913
|
+
choice(alias($._reserved_identifier, $.identifier), alias($.undefined, $.identifier), $.identifier)
|
|
914
|
+
),
|
|
915
|
+
$._call_signature
|
|
882
916
|
),
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
917
|
+
'=>',
|
|
918
|
+
sym(async ? '_async_function_start' : '_sync_function_start'),
|
|
919
|
+
choice(
|
|
920
|
+
seq(field('body', $.expression), sym('_arrow_context_end')),
|
|
921
|
+
seq(
|
|
922
|
+
field('body', $.statement_block),
|
|
923
|
+
optional(seq(sym('_arrow_function_block_end'), optional(sym('_arrow_function_block_continuation')))),
|
|
924
|
+
sym('_function_context_end')
|
|
925
|
+
)
|
|
926
|
+
),
|
|
927
|
+
optional(sym('_completed_arrow_function'))
|
|
928
|
+
)
|
|
894
929
|
)
|
|
895
930
|
),
|
|
896
931
|
|
|
@@ -923,27 +958,31 @@ module.exports = grammar({
|
|
|
923
958
|
_constructor_function_expression: ($) =>
|
|
924
959
|
prec(
|
|
925
960
|
'literal',
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
961
|
+
functionContext((async) =>
|
|
962
|
+
seq(
|
|
963
|
+
optional(sym('_constructor_async_function_start')),
|
|
964
|
+
...(async ? ['async'] : []),
|
|
965
|
+
'function',
|
|
966
|
+
field('name', optional($.identifier)),
|
|
967
|
+
$._call_signature,
|
|
968
|
+
contextBody(async, field('body', $.statement_block))
|
|
969
|
+
)
|
|
933
970
|
)
|
|
934
971
|
),
|
|
935
972
|
|
|
936
973
|
_constructor_generator_function: ($) =>
|
|
937
974
|
prec(
|
|
938
975
|
'literal',
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
976
|
+
functionContext((async) =>
|
|
977
|
+
seq(
|
|
978
|
+
optional(sym('_constructor_async_function_start')),
|
|
979
|
+
...(async ? ['async'] : []),
|
|
980
|
+
'function',
|
|
981
|
+
'*',
|
|
982
|
+
field('name', optional($.identifier)),
|
|
983
|
+
$._call_signature,
|
|
984
|
+
contextBody(async, field('body', $.statement_block))
|
|
985
|
+
)
|
|
947
986
|
)
|
|
948
987
|
),
|
|
949
988
|
|
|
@@ -1447,14 +1486,16 @@ module.exports = grammar({
|
|
|
1447
1486
|
rest_pattern: ($) => prec.right(seq('...', choice($._lhs_expression, $.parenthesized_expression))),
|
|
1448
1487
|
|
|
1449
1488
|
method_definition: ($) =>
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1489
|
+
functionContext((async) =>
|
|
1490
|
+
seq(
|
|
1491
|
+
repeat(field('decorator', $.decorator)),
|
|
1492
|
+
optional('static'),
|
|
1493
|
+
...(async ? ['async'] : []),
|
|
1494
|
+
optional(choice('get', 'set', '*')),
|
|
1495
|
+
field('name', $._property_name),
|
|
1496
|
+
field('parameters', $.formal_parameters),
|
|
1497
|
+
contextBody(async, field('body', alias($._class_member_body, $.statement_block)))
|
|
1498
|
+
)
|
|
1458
1499
|
),
|
|
1459
1500
|
|
|
1460
1501
|
// The body of a method or a static block, a rule of its own rather than statement_block: sharing it let tree-sitter
|
|
@@ -1475,7 +1516,9 @@ module.exports = grammar({
|
|
|
1475
1516
|
choice(
|
|
1476
1517
|
$.identifier,
|
|
1477
1518
|
$._escaped_let,
|
|
1478
|
-
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1519
|
+
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1520
|
+
word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
|
|
1521
|
+
)
|
|
1479
1522
|
),
|
|
1480
1523
|
sym('property_identifier')
|
|
1481
1524
|
),
|
|
@@ -1504,7 +1547,9 @@ module.exports = grammar({
|
|
|
1504
1547
|
choice(
|
|
1505
1548
|
...MEMBER_MODIFIERS,
|
|
1506
1549
|
$._escaped_let,
|
|
1507
|
-
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1550
|
+
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1551
|
+
word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
|
|
1552
|
+
)
|
|
1508
1553
|
),
|
|
1509
1554
|
|
|
1510
1555
|
_semicolon: () =>
|
|
@@ -1538,3 +1583,15 @@ function commaSep1(rule) {
|
|
|
1538
1583
|
function commaSep(rule) {
|
|
1539
1584
|
return optional(commaSep1(rule));
|
|
1540
1585
|
}
|
|
1586
|
+
|
|
1587
|
+
/** @param {(isAsync: boolean) => import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} makeRule */
|
|
1588
|
+
function functionContext(makeRule) {
|
|
1589
|
+
return choice(makeRule(false), makeRule(true));
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* @param {boolean} async
|
|
1593
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} body
|
|
1594
|
+
*/
|
|
1595
|
+
function contextBody(async, body) {
|
|
1596
|
+
return seq(sym(async ? '_async_function_start' : '_sync_function_start'), body, sym('_function_context_end'));
|
|
1597
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-javascript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "JavaScript grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
48
48
|
"@willbooster/oxlint-config": "1.4.8",
|
|
49
49
|
"@willbooster/wb": "22.26.1",
|
|
50
|
-
"@willbooster/web-tree-sitter": "2.0.
|
|
50
|
+
"@willbooster/web-tree-sitter": "2.0.27",
|
|
51
51
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
52
52
|
"lefthook": "2.2.1",
|
|
53
53
|
"oxfmt": "0.72.0",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"playwright": "1.64.0",
|
|
57
57
|
"semantic-release": "25.0.9",
|
|
58
58
|
"sort-package-json": "4.0.0",
|
|
59
|
-
"typescript": "7.0.2",
|
|
60
59
|
"vite": "8.3.4",
|
|
61
60
|
"vitest": "5.0.3",
|
|
62
61
|
"wrangler": "4.149.0"
|
package/src/node-types.json
CHANGED
|
@@ -1146,16 +1146,6 @@
|
|
|
1146
1146
|
}
|
|
1147
1147
|
]
|
|
1148
1148
|
},
|
|
1149
|
-
"decorator": {
|
|
1150
|
-
"multiple": true,
|
|
1151
|
-
"required": false,
|
|
1152
|
-
"types": [
|
|
1153
|
-
{
|
|
1154
|
-
"type": "decorator",
|
|
1155
|
-
"named": true
|
|
1156
|
-
}
|
|
1157
|
-
]
|
|
1158
|
-
},
|
|
1159
1149
|
"source": {
|
|
1160
1150
|
"multiple": false,
|
|
1161
1151
|
"required": false,
|
|
Binary file
|