@willbooster/tree-sitter-javascript 21.1.0 → 22.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/grammar.js +37 -23
- package/package.json +1 -1
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter-javascript_script.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -135,6 +135,10 @@ module.exports = grammar({
|
|
|
135
135
|
sym('_class_heritage_yield_identifier'),
|
|
136
136
|
sym('_class_heritage_await_identifier'),
|
|
137
137
|
sym('_template_escape_sequence'),
|
|
138
|
+
// The `function` and `class` keywords where a declaration may start, so that an expression statement cannot begin
|
|
139
|
+
// with them there, as ECMAScript's ExpressionStatement lookahead restriction requires.
|
|
140
|
+
sym('_declaration_function_keyword'),
|
|
141
|
+
sym('_declaration_class_keyword'),
|
|
138
142
|
],
|
|
139
143
|
|
|
140
144
|
extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
|
|
@@ -579,8 +583,10 @@ module.exports = grammar({
|
|
|
579
583
|
seq(
|
|
580
584
|
'try',
|
|
581
585
|
field('body', $.statement_block),
|
|
582
|
-
|
|
583
|
-
|
|
586
|
+
choice(
|
|
587
|
+
seq(field('handler', $.catch_clause), optional(field('finalizer', $.finally_clause))),
|
|
588
|
+
field('finalizer', $.finally_clause)
|
|
589
|
+
)
|
|
584
590
|
),
|
|
585
591
|
|
|
586
592
|
with_statement: ($) => seq('with', field('object', $.parenthesized_expression), field('body', $._single_statement)),
|
|
@@ -670,17 +676,12 @@ module.exports = grammar({
|
|
|
670
676
|
'object',
|
|
671
677
|
seq(
|
|
672
678
|
'{',
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
aliasWithAsyncKeyword(
|
|
680
|
-
choice($.identifier, $._reserved_identifier),
|
|
681
|
-
sym('shorthand_property_identifier')
|
|
682
|
-
)
|
|
683
|
-
)
|
|
679
|
+
trailingCommaSep(
|
|
680
|
+
choice(
|
|
681
|
+
$.pair,
|
|
682
|
+
$.spread_element,
|
|
683
|
+
$.method_definition,
|
|
684
|
+
aliasWithAsyncKeyword(choice($.identifier, $._reserved_identifier), sym('shorthand_property_identifier'))
|
|
684
685
|
)
|
|
685
686
|
),
|
|
686
687
|
'}'
|
|
@@ -696,14 +697,10 @@ module.exports = grammar({
|
|
|
696
697
|
sym('shorthand_property_identifier_pattern')
|
|
697
698
|
)
|
|
698
699
|
);
|
|
700
|
+
const rest = alias($._object_rest_pattern, $.rest_pattern);
|
|
699
701
|
return prec(
|
|
700
702
|
'object',
|
|
701
|
-
seq(
|
|
702
|
-
'{',
|
|
703
|
-
repeat(seq(optional(property), ',')),
|
|
704
|
-
optional(choice(property, alias($._object_rest_pattern, $.rest_pattern))),
|
|
705
|
-
'}'
|
|
706
|
-
)
|
|
703
|
+
seq('{', optional(choice(seq(commaSep1(property), optional(seq(',', optional(rest)))), rest)), '}')
|
|
707
704
|
);
|
|
708
705
|
},
|
|
709
706
|
|
|
@@ -845,7 +842,11 @@ module.exports = grammar({
|
|
|
845
842
|
'class',
|
|
846
843
|
field('name', optional($.identifier))
|
|
847
844
|
),
|
|
848
|
-
seq(
|
|
845
|
+
seq(
|
|
846
|
+
repeat(field('decorator', $.decorator)),
|
|
847
|
+
choice('class', alias(sym('_declaration_class_keyword'), 'class')),
|
|
848
|
+
field('name', $.identifier)
|
|
849
|
+
)
|
|
849
850
|
),
|
|
850
851
|
optional($.class_heritage),
|
|
851
852
|
field('body', $.class_body)
|
|
@@ -903,7 +904,11 @@ module.exports = grammar({
|
|
|
903
904
|
'function',
|
|
904
905
|
field('name', optional($.identifier))
|
|
905
906
|
),
|
|
906
|
-
seq(
|
|
907
|
+
seq(
|
|
908
|
+
...(async ? [alias(sym('_async_keyword'), 'async')] : []),
|
|
909
|
+
choice('function', alias(sym('_declaration_function_keyword'), 'function')),
|
|
910
|
+
field('name', $.identifier)
|
|
911
|
+
)
|
|
907
912
|
),
|
|
908
913
|
functionScope(async, seq($._call_signature, field('body', $.statement_block)))
|
|
909
914
|
)
|
|
@@ -939,7 +944,7 @@ module.exports = grammar({
|
|
|
939
944
|
),
|
|
940
945
|
seq(
|
|
941
946
|
...(async ? [alias(sym('_async_keyword'), 'async')] : []),
|
|
942
|
-
'function',
|
|
947
|
+
choice('function', alias(sym('_declaration_function_keyword'), 'function')),
|
|
943
948
|
'*',
|
|
944
949
|
field('name', $.identifier)
|
|
945
950
|
)
|
|
@@ -1476,7 +1481,7 @@ module.exports = grammar({
|
|
|
1476
1481
|
undefined: () => 'undefined',
|
|
1477
1482
|
|
|
1478
1483
|
arguments: ($) =>
|
|
1479
|
-
seq(choice('(', sym('_call_arguments_context')),
|
|
1484
|
+
seq(choice('(', sym('_call_arguments_context')), trailingCommaSep(choice($.expression, $.spread_element)), ')'),
|
|
1480
1485
|
|
|
1481
1486
|
decorator: ($) =>
|
|
1482
1487
|
seq(
|
|
@@ -1850,6 +1855,15 @@ function commaSep(rule) {
|
|
|
1850
1855
|
return optional(commaSep1(rule));
|
|
1851
1856
|
}
|
|
1852
1857
|
|
|
1858
|
+
/**
|
|
1859
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
1860
|
+
*
|
|
1861
|
+
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
|
1862
|
+
*/
|
|
1863
|
+
function trailingCommaSep(rule) {
|
|
1864
|
+
return optional(seq(commaSep1(rule), optional(',')));
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1853
1867
|
/** @param {(isAsync: boolean) => import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} makeRule */
|
|
1854
1868
|
function functionContext(makeRule) {
|
|
1855
1869
|
return choice(makeRule(false), makeRule(true));
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|