@willbooster/tree-sitter-javascript 6.0.0 → 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/grammar.js +117 -78
- package/package.json +1 -1
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +1 -1
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],
|
|
@@ -830,85 +835,97 @@ module.exports = grammar({
|
|
|
830
835
|
function_expression: ($) =>
|
|
831
836
|
prec(
|
|
832
837
|
'literal',
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
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
|
+
)
|
|
839
846
|
)
|
|
840
847
|
),
|
|
841
848
|
|
|
842
849
|
function_declaration: ($) =>
|
|
843
850
|
prec.right(
|
|
844
851
|
'declaration',
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
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))
|
|
852
862
|
),
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
field('body', $.statement_block)
|
|
863
|
+
$._call_signature,
|
|
864
|
+
contextBody(async, field('body', $.statement_block))
|
|
865
|
+
)
|
|
857
866
|
)
|
|
858
867
|
),
|
|
859
868
|
|
|
860
869
|
generator_function: ($) =>
|
|
861
870
|
prec(
|
|
862
871
|
'literal',
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
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
|
+
)
|
|
870
881
|
)
|
|
871
882
|
),
|
|
872
883
|
|
|
873
884
|
generator_function_declaration: ($) =>
|
|
874
885
|
prec.right(
|
|
875
886
|
'declaration',
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
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))
|
|
884
898
|
),
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
field('body', $.statement_block)
|
|
899
|
+
$._call_signature,
|
|
900
|
+
contextBody(async, field('body', $.statement_block))
|
|
901
|
+
)
|
|
889
902
|
)
|
|
890
903
|
),
|
|
891
904
|
|
|
892
905
|
arrow_function: ($) =>
|
|
893
906
|
prec.right(
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
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
|
|
900
916
|
),
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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
|
+
)
|
|
912
929
|
)
|
|
913
930
|
),
|
|
914
931
|
|
|
@@ -941,27 +958,31 @@ module.exports = grammar({
|
|
|
941
958
|
_constructor_function_expression: ($) =>
|
|
942
959
|
prec(
|
|
943
960
|
'literal',
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
+
)
|
|
951
970
|
)
|
|
952
971
|
),
|
|
953
972
|
|
|
954
973
|
_constructor_generator_function: ($) =>
|
|
955
974
|
prec(
|
|
956
975
|
'literal',
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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
|
+
)
|
|
965
986
|
)
|
|
966
987
|
),
|
|
967
988
|
|
|
@@ -1465,14 +1486,16 @@ module.exports = grammar({
|
|
|
1465
1486
|
rest_pattern: ($) => prec.right(seq('...', choice($._lhs_expression, $.parenthesized_expression))),
|
|
1466
1487
|
|
|
1467
1488
|
method_definition: ($) =>
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
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
|
+
)
|
|
1476
1499
|
),
|
|
1477
1500
|
|
|
1478
1501
|
// The body of a method or a static block, a rule of its own rather than statement_block: sharing it let tree-sitter
|
|
@@ -1493,7 +1516,9 @@ module.exports = grammar({
|
|
|
1493
1516
|
choice(
|
|
1494
1517
|
$.identifier,
|
|
1495
1518
|
$._escaped_let,
|
|
1496
|
-
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1519
|
+
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1520
|
+
word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
|
|
1521
|
+
)
|
|
1497
1522
|
),
|
|
1498
1523
|
sym('property_identifier')
|
|
1499
1524
|
),
|
|
@@ -1522,7 +1547,9 @@ module.exports = grammar({
|
|
|
1522
1547
|
choice(
|
|
1523
1548
|
...MEMBER_MODIFIERS,
|
|
1524
1549
|
$._escaped_let,
|
|
1525
|
-
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1550
|
+
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1551
|
+
word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
|
|
1552
|
+
)
|
|
1526
1553
|
),
|
|
1527
1554
|
|
|
1528
1555
|
_semicolon: () =>
|
|
@@ -1556,3 +1583,15 @@ function commaSep1(rule) {
|
|
|
1556
1583
|
function commaSep(rule) {
|
|
1557
1584
|
return optional(commaSep1(rule));
|
|
1558
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
|
Binary file
|