@willbooster/tree-sitter-javascript 15.0.1 → 17.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 +3 -2
- package/grammar.js +185 -145
- 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/README.md
CHANGED
|
@@ -70,7 +70,8 @@ parser.setLanguage(await Language.load(javascript));
|
|
|
70
70
|
|
|
71
71
|
The package also ships the node types in `src/node-types.json`, the highlight, injection, locals, and tags queries in
|
|
72
72
|
`queries/` that `tree-sitter.json` lists, and `grammar.js` for grammars that extend this one (e.g.
|
|
73
|
-
`require('@willbooster/tree-sitter-javascript/grammar')`).
|
|
73
|
+
`require('@willbooster/tree-sitter-javascript/grammar')`). Its JSDoc describes the array/formal and object-rest
|
|
74
|
+
extension hooks. The crate ships `tree-sitter.json` and `queries/` too.
|
|
74
75
|
|
|
75
76
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-javascript) and the
|
|
76
77
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter) runtime with the matching ABI. The tested version is 15.0.0:
|
|
@@ -78,7 +79,7 @@ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-
|
|
|
78
79
|
```toml
|
|
79
80
|
[dependencies]
|
|
80
81
|
tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
|
|
81
|
-
tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "
|
|
82
|
+
tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "16" }
|
|
82
83
|
```
|
|
83
84
|
|
|
84
85
|
```rust
|
package/grammar.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
// @ts-check
|
|
9
9
|
|
|
10
|
+
/** @import {GrammarSymbols, RuleOrLiteral} from '@willbooster/web-tree-sitter/dsl' */
|
|
11
|
+
|
|
10
12
|
// The CLI injects the DSL before loading this CommonJS grammar.
|
|
11
13
|
const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token, reserved } =
|
|
12
14
|
/** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
|
|
@@ -51,7 +53,6 @@ const RESERVED_WORDS = [
|
|
|
51
53
|
];
|
|
52
54
|
const NAMED_RESERVED_WORDS = new Set(['this', 'super', 'true', 'false', 'null']);
|
|
53
55
|
|
|
54
|
-
// Words that are keywords only in some positions and identifiers elsewhere.
|
|
55
56
|
const MEMBER_MODIFIERS = ['get', 'set', 'static'];
|
|
56
57
|
const CONTEXTUAL_KEYWORDS = ['async', 'await', 'let', 'of', 'using'];
|
|
57
58
|
const CLASSIC_ASSIGNMENT_OPERATORS = ['+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=', '>>=', '>>>=', '<<=', '**='];
|
|
@@ -128,6 +129,9 @@ module.exports = grammar({
|
|
|
128
129
|
sym('_call_arguments_context'),
|
|
129
130
|
sym('_async_keyword'),
|
|
130
131
|
sym('_line_break_before_from'),
|
|
132
|
+
sym('_class_heritage_end'),
|
|
133
|
+
sym('_class_heritage_yield_identifier'),
|
|
134
|
+
sym('_class_heritage_await_identifier'),
|
|
131
135
|
],
|
|
132
136
|
|
|
133
137
|
extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
|
|
@@ -146,6 +150,8 @@ module.exports = grammar({
|
|
|
146
150
|
$._binary_operand,
|
|
147
151
|
$._unary_operand,
|
|
148
152
|
$.primary_expression,
|
|
153
|
+
$._class_heritage_expression,
|
|
154
|
+
$._class_heritage_primary,
|
|
149
155
|
$.pattern,
|
|
150
156
|
$._non_rest_pattern,
|
|
151
157
|
$._rest_pattern,
|
|
@@ -167,6 +173,7 @@ module.exports = grammar({
|
|
|
167
173
|
$._semicolon,
|
|
168
174
|
$._identifier,
|
|
169
175
|
$._reserved_identifier,
|
|
176
|
+
$._expression_identifier,
|
|
170
177
|
$._jsx_attribute,
|
|
171
178
|
$._jsx_element_name,
|
|
172
179
|
$._jsx_child,
|
|
@@ -175,6 +182,7 @@ module.exports = grammar({
|
|
|
175
182
|
$._jsx_attribute_value,
|
|
176
183
|
$._jsx_identifier,
|
|
177
184
|
$._lhs_expression,
|
|
185
|
+
$._object_rest_target,
|
|
178
186
|
],
|
|
179
187
|
|
|
180
188
|
precedences: ($) => [
|
|
@@ -219,8 +227,10 @@ module.exports = grammar({
|
|
|
219
227
|
[$._simple_target_primary, $._non_rest_pattern],
|
|
220
228
|
[$._primary_atom, $._simple_target_primary, $._non_rest_pattern],
|
|
221
229
|
[$._call_callee, $.call_expression],
|
|
230
|
+
[$._class_heritage_expression, $._class_heritage_call],
|
|
222
231
|
[$.for_in_clause, $._primary_atom],
|
|
223
232
|
[$._primary_atom, $.rest_pattern],
|
|
233
|
+
[$._primary_atom, $._object_rest_pattern],
|
|
224
234
|
[$._primary_atom, $._non_rest_pattern],
|
|
225
235
|
[$.arrow_function, $._primary_atom],
|
|
226
236
|
[$._primary_atom, $.await_expression],
|
|
@@ -228,6 +238,7 @@ module.exports = grammar({
|
|
|
228
238
|
[$.primary_expression, $._assignment_call_primary],
|
|
229
239
|
[$._local_export_specifier, $._module_export_name],
|
|
230
240
|
[$.primary_expression, $.rest_pattern],
|
|
241
|
+
[$.primary_expression, $._object_rest_pattern],
|
|
231
242
|
[$.primary_expression, $._non_rest_pattern],
|
|
232
243
|
[$.primary_expression, $.for_in_clause],
|
|
233
244
|
[$.array, $.array_pattern],
|
|
@@ -246,10 +257,6 @@ module.exports = grammar({
|
|
|
246
257
|
|
|
247
258
|
hash_bang_line: () => /#![^\n\r\u2028\u2029]*/,
|
|
248
259
|
|
|
249
|
-
//
|
|
250
|
-
// Export declarations
|
|
251
|
-
//
|
|
252
|
-
|
|
253
260
|
export_statement: ($) =>
|
|
254
261
|
choice(
|
|
255
262
|
field('declaration', alias($._decorated_export_declaration, $.declaration)),
|
|
@@ -324,10 +331,6 @@ module.exports = grammar({
|
|
|
324
331
|
$.using_declaration
|
|
325
332
|
),
|
|
326
333
|
|
|
327
|
-
//
|
|
328
|
-
// Import declarations
|
|
329
|
-
//
|
|
330
|
-
|
|
331
334
|
import: () => token('import'),
|
|
332
335
|
|
|
333
336
|
import_statement: ($) =>
|
|
@@ -360,10 +363,6 @@ module.exports = grammar({
|
|
|
360
363
|
|
|
361
364
|
import_attribute: ($) => seq('with', $.object),
|
|
362
365
|
|
|
363
|
-
//
|
|
364
|
-
// Statements
|
|
365
|
-
//
|
|
366
|
-
|
|
367
366
|
statement: ($) =>
|
|
368
367
|
choice(
|
|
369
368
|
$.export_statement,
|
|
@@ -617,10 +616,6 @@ module.exports = grammar({
|
|
|
617
616
|
field('body', $._single_statement)
|
|
618
617
|
),
|
|
619
618
|
|
|
620
|
-
//
|
|
621
|
-
// Statement components
|
|
622
|
-
//
|
|
623
|
-
|
|
624
619
|
switch_body: ($) => seq('{', repeat(choice($.switch_case, $.switch_default)), '}'),
|
|
625
620
|
|
|
626
621
|
switch_case: ($) => seq('case', field('value', $._expressions), ':', field('body', repeat($._statement))),
|
|
@@ -638,9 +633,6 @@ module.exports = grammar({
|
|
|
638
633
|
|
|
639
634
|
parenthesized_expression: ($) => seq('(', $._expressions, ')'),
|
|
640
635
|
|
|
641
|
-
//
|
|
642
|
-
// Expressions
|
|
643
|
-
//
|
|
644
636
|
_expressions: ($) => choice($.expression, $.sequence_expression),
|
|
645
637
|
|
|
646
638
|
expression: ($) =>
|
|
@@ -661,16 +653,7 @@ module.exports = grammar({
|
|
|
661
653
|
|
|
662
654
|
_unary_operand: ($) => choice($.primary_expression, $.await_expression, $.unary_expression, $.update_expression),
|
|
663
655
|
|
|
664
|
-
primary_expression: ($) =>
|
|
665
|
-
choice(
|
|
666
|
-
$._primary_atom,
|
|
667
|
-
$.subscript_expression,
|
|
668
|
-
$.member_expression,
|
|
669
|
-
$.call_expression,
|
|
670
|
-
$.new_expression,
|
|
671
|
-
alias($._argumentless_new_expression, $.new_expression),
|
|
672
|
-
$.arrow_function
|
|
673
|
-
),
|
|
656
|
+
primary_expression: ($) => choice(leftHandSideExpression($), $.arrow_function),
|
|
674
657
|
|
|
675
658
|
yield_expression: ($) =>
|
|
676
659
|
prec.right(
|
|
@@ -713,7 +696,12 @@ module.exports = grammar({
|
|
|
713
696
|
);
|
|
714
697
|
return prec(
|
|
715
698
|
'object',
|
|
716
|
-
seq(
|
|
699
|
+
seq(
|
|
700
|
+
'{',
|
|
701
|
+
repeat(seq(optional(property), ',')),
|
|
702
|
+
optional(choice(property, alias($._object_rest_pattern, $.rest_pattern))),
|
|
703
|
+
'}'
|
|
704
|
+
)
|
|
717
705
|
);
|
|
718
706
|
},
|
|
719
707
|
|
|
@@ -751,9 +739,6 @@ module.exports = grammar({
|
|
|
751
739
|
jsx_element: ($) =>
|
|
752
740
|
seq(field('open_tag', $.jsx_opening_element), repeat($._jsx_child), field('close_tag', $.jsx_closing_element)),
|
|
753
741
|
|
|
754
|
-
// An entity can be named, numeric (decimal), or numeric (hexadecimal). The
|
|
755
|
-
// longest entity name is 29 characters long, and the HTML spec says that
|
|
756
|
-
// no more will ever be added.
|
|
757
742
|
html_character_reference: () => /&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});/,
|
|
758
743
|
|
|
759
744
|
jsx_expression: ($) => seq('{', optional(choice($.expression, $.sequence_expression, $.spread_element)), '}'),
|
|
@@ -825,13 +810,8 @@ module.exports = grammar({
|
|
|
825
810
|
)
|
|
826
811
|
),
|
|
827
812
|
|
|
828
|
-
// Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
|
|
829
|
-
// We give names to the token() constructs containing a regexp
|
|
830
|
-
// so as to obtain a node in the CST.
|
|
831
|
-
//
|
|
832
813
|
unescaped_double_jsx_string_fragment: () => token.immediate(prec(1, /([^"&]|&[^#A-Za-z"&])+/)),
|
|
833
814
|
|
|
834
|
-
// same here
|
|
835
815
|
unescaped_single_jsx_string_fragment: () => token.immediate(prec(1, /([^'&]|&[^#A-Za-z'&])+/)),
|
|
836
816
|
|
|
837
817
|
// An `&` that does not start a complete html_character_reference is a literal character, as in HTML. The lexer
|
|
@@ -870,7 +850,31 @@ module.exports = grammar({
|
|
|
870
850
|
)
|
|
871
851
|
),
|
|
872
852
|
|
|
873
|
-
class_heritage: ($) =>
|
|
853
|
+
class_heritage: ($) =>
|
|
854
|
+
seq('extends', alias($._class_heritage_expression, $.expression), sym('_class_heritage_end')),
|
|
855
|
+
|
|
856
|
+
_class_heritage_expression: ($) => alias($._class_heritage_primary, $.primary_expression),
|
|
857
|
+
|
|
858
|
+
_class_heritage_primary: ($) =>
|
|
859
|
+
leftHandSideExpression($, {
|
|
860
|
+
atom: $._class_heritage_atom,
|
|
861
|
+
call: alias($._class_heritage_call, $.call_expression),
|
|
862
|
+
member: alias($._class_heritage_member, $.member_expression),
|
|
863
|
+
subscript: alias($._class_heritage_subscript, $.subscript_expression),
|
|
864
|
+
}),
|
|
865
|
+
|
|
866
|
+
_class_heritage_atom: ($) => primaryAtom($, $._expression_identifier),
|
|
867
|
+
|
|
868
|
+
_class_heritage_call: ($) =>
|
|
869
|
+
callExpression(
|
|
870
|
+
$,
|
|
871
|
+
alias($._class_heritage_expression, $.expression),
|
|
872
|
+
alias($._class_heritage_primary, $.primary_expression)
|
|
873
|
+
),
|
|
874
|
+
|
|
875
|
+
_class_heritage_member: ($) => memberExpression($, alias($._class_heritage_expression, $.expression)),
|
|
876
|
+
|
|
877
|
+
_class_heritage_subscript: ($) => subscriptExpression($, alias($._class_heritage_expression, $.expression)),
|
|
874
878
|
|
|
875
879
|
function_expression: ($) =>
|
|
876
880
|
prec(
|
|
@@ -983,46 +987,9 @@ module.exports = grammar({
|
|
|
983
987
|
|
|
984
988
|
optional_chain: () => '?.',
|
|
985
989
|
|
|
986
|
-
call_expression: ($) =>
|
|
987
|
-
choice(
|
|
988
|
-
prec(
|
|
989
|
-
'call',
|
|
990
|
-
seq(field('function', choice(alias($._call_callee, $.expression), $.import)), field('arguments', $.arguments))
|
|
991
|
-
),
|
|
992
|
-
prec('template_call', seq(field('function', $.primary_expression), field('arguments', $.template_string))),
|
|
993
|
-
prec(
|
|
994
|
-
'member',
|
|
995
|
-
seq(
|
|
996
|
-
field('function', $.primary_expression),
|
|
997
|
-
field('optional_chain', $.optional_chain),
|
|
998
|
-
field('arguments', $.arguments)
|
|
999
|
-
)
|
|
1000
|
-
)
|
|
1001
|
-
),
|
|
990
|
+
call_expression: ($) => callExpression($, alias($._call_callee, $.expression), $.primary_expression),
|
|
1002
991
|
|
|
1003
|
-
_primary_atom: ($) =>
|
|
1004
|
-
choice(
|
|
1005
|
-
$._jsx_element,
|
|
1006
|
-
$.parenthesized_expression,
|
|
1007
|
-
$._identifier,
|
|
1008
|
-
alias(sym('_await_yield_identifier'), $.identifier),
|
|
1009
|
-
aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
|
|
1010
|
-
$.this,
|
|
1011
|
-
$.super,
|
|
1012
|
-
$.number,
|
|
1013
|
-
$.string,
|
|
1014
|
-
$.template_string,
|
|
1015
|
-
$.regex,
|
|
1016
|
-
$.true,
|
|
1017
|
-
$.false,
|
|
1018
|
-
$.null,
|
|
1019
|
-
$.object,
|
|
1020
|
-
$.array,
|
|
1021
|
-
$.function_expression,
|
|
1022
|
-
$.generator_function,
|
|
1023
|
-
$.class,
|
|
1024
|
-
$.meta_property
|
|
1025
|
-
),
|
|
992
|
+
_primary_atom: ($) => primaryAtom($, $._reserved_identifier),
|
|
1026
993
|
|
|
1027
994
|
_assignment_call: ($) =>
|
|
1028
995
|
prec(
|
|
@@ -1212,33 +1179,9 @@ module.exports = grammar({
|
|
|
1212
1179
|
)
|
|
1213
1180
|
),
|
|
1214
1181
|
|
|
1215
|
-
member_expression: ($) =>
|
|
1216
|
-
prec(
|
|
1217
|
-
'member',
|
|
1218
|
-
seq(
|
|
1219
|
-
field('object', choice(alias($._call_callee, $.expression), $.import)),
|
|
1220
|
-
choice('.', field('optional_chain', $.optional_chain)),
|
|
1221
|
-
field(
|
|
1222
|
-
'property',
|
|
1223
|
-
choice(
|
|
1224
|
-
$.private_property_identifier,
|
|
1225
|
-
reserved('properties', alias($.identifier, sym('property_identifier')))
|
|
1226
|
-
)
|
|
1227
|
-
)
|
|
1228
|
-
)
|
|
1229
|
-
),
|
|
1182
|
+
member_expression: ($) => memberExpression($, alias($._call_callee, $.expression)),
|
|
1230
1183
|
|
|
1231
|
-
subscript_expression: ($) =>
|
|
1232
|
-
prec.right(
|
|
1233
|
-
'member',
|
|
1234
|
-
seq(
|
|
1235
|
-
field('object', alias($._call_callee, $.expression)),
|
|
1236
|
-
optional(field('optional_chain', $.optional_chain)),
|
|
1237
|
-
'[',
|
|
1238
|
-
field('index', $._expressions),
|
|
1239
|
-
']'
|
|
1240
|
-
)
|
|
1241
|
-
),
|
|
1184
|
+
subscript_expression: ($) => subscriptExpression($, alias($._call_callee, $.expression)),
|
|
1242
1185
|
|
|
1243
1186
|
_lhs_expression: ($) =>
|
|
1244
1187
|
choice(
|
|
@@ -1403,10 +1346,6 @@ module.exports = grammar({
|
|
|
1403
1346
|
|
|
1404
1347
|
sequence_expression: ($) => prec.right(commaSep1($.expression)),
|
|
1405
1348
|
|
|
1406
|
-
//
|
|
1407
|
-
// Primitives
|
|
1408
|
-
//
|
|
1409
|
-
|
|
1410
1349
|
string: ($) =>
|
|
1411
1350
|
choice(
|
|
1412
1351
|
seq(
|
|
@@ -1421,13 +1360,8 @@ module.exports = grammar({
|
|
|
1421
1360
|
)
|
|
1422
1361
|
),
|
|
1423
1362
|
|
|
1424
|
-
// Workaround to https://github.com/tree-sitter/tree-sitter/issues/1156
|
|
1425
|
-
// We give names to the token() constructs containing a regexp
|
|
1426
|
-
// so as to obtain a node in the CST.
|
|
1427
|
-
//
|
|
1428
1363
|
unescaped_double_string_fragment: () => token.immediate(prec(1, /[^"\\\r\n]+/)),
|
|
1429
1364
|
|
|
1430
|
-
// same here
|
|
1431
1365
|
unescaped_single_string_fragment: () => token.immediate(prec(1, /[^'\\\r\n]+/)),
|
|
1432
1366
|
|
|
1433
1367
|
escape_sequence: () =>
|
|
@@ -1475,19 +1409,10 @@ module.exports = grammar({
|
|
|
1475
1409
|
-1,
|
|
1476
1410
|
repeat1(
|
|
1477
1411
|
choice(
|
|
1478
|
-
seq(
|
|
1479
|
-
|
|
1480
|
-
repeat(
|
|
1481
|
-
choice(
|
|
1482
|
-
seq('\\', /[^\n\r\u2028\u2029]/), // escaped character
|
|
1483
|
-
/[^\]\\\n\r\u2028\u2029]/ // any character besides ']', '\', or a line terminator
|
|
1484
|
-
)
|
|
1485
|
-
),
|
|
1486
|
-
']'
|
|
1487
|
-
), // square-bracket-delimited character class
|
|
1488
|
-
seq('\\', /[^\n\r\u2028\u2029]/), // escaped character
|
|
1412
|
+
seq('[', repeat(choice(seq('\\', /[^\n\r\u2028\u2029]/), /[^\]\\\n\r\u2028\u2029]/)), ']'),
|
|
1413
|
+
seq('\\', /[^\n\r\u2028\u2029]/),
|
|
1489
1414
|
// oxlint-disable-next-line no-useless-escape -- tree-sitter's regex parser rejects an unescaped `[` in a character class.
|
|
1490
|
-
/[^/\\\[\n\r\u2028\u2029]/
|
|
1415
|
+
/[^/\\\[\n\r\u2028\u2029]/
|
|
1491
1416
|
)
|
|
1492
1417
|
)
|
|
1493
1418
|
)
|
|
@@ -1561,10 +1486,6 @@ module.exports = grammar({
|
|
|
1561
1486
|
null: () => 'null',
|
|
1562
1487
|
undefined: () => 'undefined',
|
|
1563
1488
|
|
|
1564
|
-
//
|
|
1565
|
-
// Expression components
|
|
1566
|
-
//
|
|
1567
|
-
|
|
1568
1489
|
arguments: ($) =>
|
|
1569
1490
|
seq(choice('(', sym('_call_arguments_context')), commaSep(optional(choice($.expression, $.spread_element))), ')'),
|
|
1570
1491
|
|
|
@@ -1669,8 +1590,8 @@ module.exports = grammar({
|
|
|
1669
1590
|
class_static_block: ($) => seq('static', field('body', alias($._class_member_body, $.statement_block))),
|
|
1670
1591
|
|
|
1671
1592
|
/**
|
|
1672
|
-
* Canonical pattern supertype. Extend `_non_rest_pattern` for non-rest forms
|
|
1673
|
-
*
|
|
1593
|
+
* Canonical pattern supertype. Extend `_non_rest_pattern` for non-rest forms;
|
|
1594
|
+
* overriding only `pattern` does not extend ordinary slots.
|
|
1674
1595
|
*/
|
|
1675
1596
|
pattern: ($) => choice(alias($._non_rest_pattern, $.pattern), alias($._rest_pattern, $.pattern)),
|
|
1676
1597
|
|
|
@@ -1680,11 +1601,28 @@ module.exports = grammar({
|
|
|
1680
1601
|
|
|
1681
1602
|
_rest_pattern: ($) => prec.dynamic(-1, $.rest_pattern),
|
|
1682
1603
|
|
|
1604
|
+
/** Array-pattern and formal-parameter rest syntax; object rest uses `_object_rest_pattern`. */
|
|
1683
1605
|
rest_pattern: ($) =>
|
|
1684
1606
|
prec.right(
|
|
1685
1607
|
seq('...', choice($._lhs_expression, alias($._parenthesized_simple_target, $.parenthesized_expression)))
|
|
1686
1608
|
),
|
|
1687
1609
|
|
|
1610
|
+
/**
|
|
1611
|
+
* Object-rest syntax, aliased to public `rest_pattern`. Extend `_object_rest_target`
|
|
1612
|
+
* for target forms; `rest_pattern` and `_lhs_expression` overrides do not extend object rest.
|
|
1613
|
+
*/
|
|
1614
|
+
_object_rest_pattern: ($) => prec.right(seq('...', $._object_rest_target)),
|
|
1615
|
+
|
|
1616
|
+
/** Object-rest reference targets, excluding nested destructuring patterns. */
|
|
1617
|
+
_object_rest_target: ($) =>
|
|
1618
|
+
choice(
|
|
1619
|
+
$.member_expression,
|
|
1620
|
+
$.subscript_expression,
|
|
1621
|
+
$._identifier,
|
|
1622
|
+
aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
|
|
1623
|
+
alias($._parenthesized_simple_target, $.parenthesized_expression)
|
|
1624
|
+
),
|
|
1625
|
+
|
|
1688
1626
|
method_definition: ($) =>
|
|
1689
1627
|
functionContext((async) =>
|
|
1690
1628
|
choice(
|
|
@@ -1768,15 +1706,9 @@ module.exports = grammar({
|
|
|
1768
1706
|
|
|
1769
1707
|
computed_property_name: ($) => seq('[', $.expression, ']'),
|
|
1770
1708
|
|
|
1771
|
-
_reserved_identifier: ($) =>
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
...MEMBER_MODIFIERS,
|
|
1775
|
-
$._escaped_let,
|
|
1776
|
-
...CONTEXTUAL_KEYWORDS.map((word) =>
|
|
1777
|
-
word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
|
|
1778
|
-
)
|
|
1779
|
-
),
|
|
1709
|
+
_reserved_identifier: ($) => contextualIdentifier($, false),
|
|
1710
|
+
|
|
1711
|
+
_expression_identifier: ($) => contextualIdentifier($, true),
|
|
1780
1712
|
|
|
1781
1713
|
_semicolon: () =>
|
|
1782
1714
|
choice(
|
|
@@ -1788,6 +1720,118 @@ module.exports = grammar({
|
|
|
1788
1720
|
},
|
|
1789
1721
|
});
|
|
1790
1722
|
|
|
1723
|
+
/**
|
|
1724
|
+
* @param {GrammarSymbols<'_primary_atom' | 'subscript_expression' | 'member_expression' | 'call_expression' | 'new_expression' | '_argumentless_new_expression'>} $
|
|
1725
|
+
* @param {{atom?: RuleOrLiteral, subscript?: RuleOrLiteral, member?: RuleOrLiteral, call?: RuleOrLiteral}} [forms]
|
|
1726
|
+
*/
|
|
1727
|
+
function leftHandSideExpression($, forms = {}) {
|
|
1728
|
+
return choice(
|
|
1729
|
+
forms.atom ?? $._primary_atom,
|
|
1730
|
+
forms.subscript ?? $.subscript_expression,
|
|
1731
|
+
forms.member ?? $.member_expression,
|
|
1732
|
+
forms.call ?? $.call_expression,
|
|
1733
|
+
$.new_expression,
|
|
1734
|
+
alias($._argumentless_new_expression, $.new_expression)
|
|
1735
|
+
);
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
/**
|
|
1739
|
+
* @param {import('@willbooster/web-tree-sitter/dsl').GrammarSymbols<'_escaped_let'>} $
|
|
1740
|
+
* @param {boolean} heritage
|
|
1741
|
+
*/
|
|
1742
|
+
function contextualIdentifier($, heritage) {
|
|
1743
|
+
const yieldWord = heritage ? sym('_class_heritage_yield_identifier') : sym('_yield_identifier');
|
|
1744
|
+
const awaitWord = heritage
|
|
1745
|
+
? sym('_class_heritage_await_identifier')
|
|
1746
|
+
: choice(sym('_await_keyword'), sym('_await_identifier'));
|
|
1747
|
+
return choice(
|
|
1748
|
+
yieldWord,
|
|
1749
|
+
...MEMBER_MODIFIERS,
|
|
1750
|
+
$._escaped_let,
|
|
1751
|
+
...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? awaitWord : word))
|
|
1752
|
+
);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
/**
|
|
1756
|
+
* @param {GrammarSymbols<'import' | 'arguments' | 'template_string' | 'optional_chain'>} $
|
|
1757
|
+
* @param {RuleOrLiteral} callee
|
|
1758
|
+
* @param {RuleOrLiteral} primary
|
|
1759
|
+
*/
|
|
1760
|
+
function callExpression($, callee, primary) {
|
|
1761
|
+
return choice(
|
|
1762
|
+
prec('call', seq(field('function', choice(callee, $.import)), field('arguments', $.arguments))),
|
|
1763
|
+
prec('template_call', seq(field('function', primary), field('arguments', $.template_string))),
|
|
1764
|
+
prec(
|
|
1765
|
+
'member',
|
|
1766
|
+
seq(field('function', primary), field('optional_chain', $.optional_chain), field('arguments', $.arguments))
|
|
1767
|
+
)
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
/**
|
|
1772
|
+
* @param {GrammarSymbols<'_jsx_element' | 'parenthesized_expression' | '_identifier' | 'identifier' | 'this' | 'super' | 'number' | 'string' | 'template_string' | 'regex' | 'true' | 'false' | 'null' | 'object' | 'array' | 'function_expression' | 'generator_function' | 'class' | 'meta_property'>} $
|
|
1773
|
+
* @param {RuleOrLiteral} identifier
|
|
1774
|
+
*/
|
|
1775
|
+
function primaryAtom($, identifier) {
|
|
1776
|
+
return choice(
|
|
1777
|
+
$._jsx_element,
|
|
1778
|
+
$.parenthesized_expression,
|
|
1779
|
+
$._identifier,
|
|
1780
|
+
alias(sym('_await_yield_identifier'), $.identifier),
|
|
1781
|
+
aliasWithAsyncKeyword(identifier, $.identifier),
|
|
1782
|
+
$.this,
|
|
1783
|
+
$.super,
|
|
1784
|
+
$.number,
|
|
1785
|
+
$.string,
|
|
1786
|
+
$.template_string,
|
|
1787
|
+
$.regex,
|
|
1788
|
+
$.true,
|
|
1789
|
+
$.false,
|
|
1790
|
+
$.null,
|
|
1791
|
+
$.object,
|
|
1792
|
+
$.array,
|
|
1793
|
+
$.function_expression,
|
|
1794
|
+
$.generator_function,
|
|
1795
|
+
$.class,
|
|
1796
|
+
$.meta_property
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* @param {GrammarSymbols<'import' | 'optional_chain' | 'private_property_identifier' | 'identifier'>} $
|
|
1802
|
+
* @param {RuleOrLiteral} object
|
|
1803
|
+
*/
|
|
1804
|
+
function memberExpression($, object) {
|
|
1805
|
+
return prec(
|
|
1806
|
+
'member',
|
|
1807
|
+
seq(
|
|
1808
|
+
field('object', choice(object, $.import)),
|
|
1809
|
+
choice('.', field('optional_chain', $.optional_chain)),
|
|
1810
|
+
field(
|
|
1811
|
+
'property',
|
|
1812
|
+
choice($.private_property_identifier, reserved('properties', alias($.identifier, sym('property_identifier'))))
|
|
1813
|
+
)
|
|
1814
|
+
)
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* @param {GrammarSymbols<'optional_chain' | '_expressions'>} $
|
|
1820
|
+
* @param {RuleOrLiteral} object
|
|
1821
|
+
*/
|
|
1822
|
+
function subscriptExpression($, object) {
|
|
1823
|
+
return prec.right(
|
|
1824
|
+
'member',
|
|
1825
|
+
seq(
|
|
1826
|
+
field('object', object),
|
|
1827
|
+
optional(field('optional_chain', $.optional_chain)),
|
|
1828
|
+
'[',
|
|
1829
|
+
field('index', $._expressions),
|
|
1830
|
+
']'
|
|
1831
|
+
)
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1791
1835
|
/**
|
|
1792
1836
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
1793
1837
|
* @param {import('@willbooster/web-tree-sitter/dsl').SymbolRule<string>} symbol
|
|
@@ -1797,8 +1841,6 @@ function aliasWithAsyncKeyword(rule, symbol) {
|
|
|
1797
1841
|
}
|
|
1798
1842
|
|
|
1799
1843
|
/**
|
|
1800
|
-
* Creates a rule to match one or more of the rules separated by a comma
|
|
1801
|
-
*
|
|
1802
1844
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
1803
1845
|
*
|
|
1804
1846
|
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
@@ -1808,8 +1850,6 @@ function commaSep1(rule) {
|
|
|
1808
1850
|
}
|
|
1809
1851
|
|
|
1810
1852
|
/**
|
|
1811
|
-
* Creates a rule to optionally match one or more of the rules separated by a comma
|
|
1812
|
-
*
|
|
1813
1853
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
1814
1854
|
*
|
|
1815
1855
|
* @returns {import('@willbooster/web-tree-sitter/dsl').ChoiceRule}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|