@willbooster/tree-sitter-typescript 1.3.2 → 1.3.4
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/common/defineGrammar.js +47 -16
- package/package.json +2 -2
- package/tree-sitter-tsx.wasm +0 -0
- package/tree-sitter-typescript.wasm +0 -0
- package/tree-sitter.json +1 -1
- package/tsx/src/node-types.json +16 -8
package/common/defineGrammar.js
CHANGED
|
@@ -70,6 +70,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
70
70
|
$._global_declaration_start,
|
|
71
71
|
$._global_declaration_end,
|
|
72
72
|
$.__error_recovery,
|
|
73
|
+
$._namespace_expression_end,
|
|
73
74
|
],
|
|
74
75
|
|
|
75
76
|
supertypes: ($, previous) => [...previous, $.type, $.primary_type],
|
|
@@ -145,6 +146,9 @@ module.exports = function defineGrammar(dialect) {
|
|
|
145
146
|
],
|
|
146
147
|
|
|
147
148
|
conflicts: ($, previous) => [
|
|
149
|
+
[$.export_specifier, $._local_export_specifier, $._module_export_name],
|
|
150
|
+
[$.export_specifier, $._module_export_name],
|
|
151
|
+
[$.export_specifier, $._local_export_specifier],
|
|
148
152
|
...withTypeArgumentsTarget($, previous),
|
|
149
153
|
[$._type_arguments_target, $.using_declaration],
|
|
150
154
|
[$._type_arguments_target, $._for_header, $._for_using_declaration],
|
|
@@ -386,6 +390,23 @@ module.exports = function defineGrammar(dialect) {
|
|
|
386
390
|
|
|
387
391
|
_lhs_expression: ($, previous) => choice(previous, $.non_null_expression),
|
|
388
392
|
|
|
393
|
+
await_expression: (_, previous) => {
|
|
394
|
+
const members = previous.content.content.members;
|
|
395
|
+
const guardIndex = members.findIndex(
|
|
396
|
+
(member) => member.type === 'SYMBOL' && member.name === '_await_operand_end'
|
|
397
|
+
);
|
|
398
|
+
if (guardIndex === -1) {
|
|
399
|
+
throw new Error('JavaScript await_expression must have a bare _await_operand_end member');
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
...previous,
|
|
403
|
+
content: {
|
|
404
|
+
...previous.content,
|
|
405
|
+
content: seq(...members.map((member, index) => (index === guardIndex ? optional(member) : member))),
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
},
|
|
409
|
+
|
|
389
410
|
primary_expression: ($) =>
|
|
390
411
|
choice($._type_arguments_target, alias($._argumentless_new_expression, $.new_expression)),
|
|
391
412
|
|
|
@@ -393,20 +414,19 @@ module.exports = function defineGrammar(dialect) {
|
|
|
393
414
|
// after `new A` to the `new` (`new A<T>()`, `new new A<T>()`), so a `new` without arguments takes none.
|
|
394
415
|
_type_arguments_target: ($) => {
|
|
395
416
|
const members = JavaScript.grammar.rules.primary_expression.members.filter(
|
|
396
|
-
(member) =>
|
|
417
|
+
(member) =>
|
|
418
|
+
(member.type !== 'ALIAS' || member.content.name !== '_argumentless_new_expression') &&
|
|
419
|
+
(dialect !== 'typescript' || member.name !== '_jsx_element')
|
|
397
420
|
);
|
|
398
421
|
return choice(...members, $.non_null_expression);
|
|
399
422
|
},
|
|
400
423
|
|
|
401
|
-
// If the dialect is regular typescript, we exclude JSX expressions and
|
|
402
|
-
// include type assertions. If the dialect is TSX, we do the opposite.
|
|
403
424
|
expression: ($, previous) => {
|
|
404
425
|
const choices = [$.as_expression, $.satisfies_expression, $.instantiation_expression, $.internal_module];
|
|
405
426
|
const members = previous.members;
|
|
406
427
|
|
|
407
428
|
if (dialect === 'typescript') {
|
|
408
|
-
choices.push($.type_assertion);
|
|
409
|
-
choices.push(...members.filter((member) => member.name !== '_jsx_element'));
|
|
429
|
+
choices.push($.type_assertion, ...members);
|
|
410
430
|
} else if (dialect === 'tsx') {
|
|
411
431
|
choices.push(...members);
|
|
412
432
|
} else {
|
|
@@ -475,9 +495,21 @@ module.exports = function defineGrammar(dialect) {
|
|
|
475
495
|
// tsx only. See jsx_opening_element.
|
|
476
496
|
jsx_self_closing_element: ($) => prec.dynamic(-1, seq($._jsx_start_opening_element, '/>')),
|
|
477
497
|
|
|
478
|
-
export_specifier: (
|
|
498
|
+
export_specifier: ($) => {
|
|
499
|
+
const name = choice($._module_export_name, alias('as', $.identifier));
|
|
500
|
+
const specifier = seq(field('name', name), optional(seq('as', field('alias', name))));
|
|
501
|
+
return choice(specifier, prec.dynamic(1, seq(choice('type', 'typeof'), specifier)));
|
|
502
|
+
},
|
|
503
|
+
|
|
504
|
+
_module_export_name: ($, previous) => choice(previous, alias('type', $.identifier)),
|
|
479
505
|
|
|
480
|
-
_local_export_specifier: (
|
|
506
|
+
_local_export_specifier: ($) => {
|
|
507
|
+
const specifier = seq(
|
|
508
|
+
field('name', choice($.identifier, alias('type', $.identifier), alias('as', $.identifier), $.string)),
|
|
509
|
+
optional(seq('as', field('alias', choice($._module_export_name, alias('as', $.identifier)))))
|
|
510
|
+
);
|
|
511
|
+
return choice(specifier, prec.dynamic(1, seq(choice('type', 'typeof'), specifier)));
|
|
512
|
+
},
|
|
481
513
|
|
|
482
514
|
_import_identifier: ($) => choice($.identifier, alias('type', $.identifier)),
|
|
483
515
|
|
|
@@ -486,11 +518,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
486
518
|
optional(choice('type', 'typeof')),
|
|
487
519
|
choice(
|
|
488
520
|
field('name', $._import_identifier),
|
|
489
|
-
seq(
|
|
490
|
-
field('name', choice($._module_export_name, alias('type', $.identifier))),
|
|
491
|
-
'as',
|
|
492
|
-
field('alias', $._import_identifier)
|
|
493
|
-
)
|
|
521
|
+
seq(field('name', $._module_export_name), 'as', field('alias', $._import_identifier))
|
|
494
522
|
)
|
|
495
523
|
),
|
|
496
524
|
|
|
@@ -526,14 +554,14 @@ module.exports = function defineGrammar(dialect) {
|
|
|
526
554
|
// variable named `using`.
|
|
527
555
|
using_declaration: ($) =>
|
|
528
556
|
seq(
|
|
529
|
-
field('kind', choice('using', seq('await', 'using'))),
|
|
557
|
+
field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
|
|
530
558
|
commaSep1(alias($._using_declarator, $.variable_declarator)),
|
|
531
559
|
$._semicolon
|
|
532
560
|
),
|
|
533
561
|
|
|
534
562
|
_for_using_declaration: ($) =>
|
|
535
563
|
seq(
|
|
536
|
-
field('kind', choice('using', seq('await', 'using'))),
|
|
564
|
+
field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
|
|
537
565
|
commaSep1(alias($._using_declarator, $.variable_declarator)),
|
|
538
566
|
';'
|
|
539
567
|
),
|
|
@@ -559,7 +587,10 @@ module.exports = function defineGrammar(dialect) {
|
|
|
559
587
|
field('kind', choice('let', 'const')),
|
|
560
588
|
field('left', choice($._binding_identifier, $._destructuring_pattern))
|
|
561
589
|
),
|
|
562
|
-
seq(
|
|
590
|
+
seq(
|
|
591
|
+
field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
|
|
592
|
+
field('left', $._binding_identifier)
|
|
593
|
+
)
|
|
563
594
|
),
|
|
564
595
|
field('operator', choice('in', 'of')),
|
|
565
596
|
field('right', $._expressions),
|
|
@@ -799,7 +830,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
799
830
|
|
|
800
831
|
module: ($) => seq('module', $._module),
|
|
801
832
|
|
|
802
|
-
internal_module: ($) => seq('namespace', $._module),
|
|
833
|
+
internal_module: ($) => seq('namespace', $._module, optional($._namespace_expression_end)),
|
|
803
834
|
|
|
804
835
|
global_declaration: ($) =>
|
|
805
836
|
seq(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-typescript",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "TypeScript and TSX grammars for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@vitest/browser-playwright": "5.0.2",
|
|
54
54
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
55
55
|
"@willbooster/oxlint-config": "1.4.8",
|
|
56
|
-
"@willbooster/tree-sitter-javascript": "1.0.
|
|
56
|
+
"@willbooster/tree-sitter-javascript": "1.0.25",
|
|
57
57
|
"@willbooster/wb": "22.18.0",
|
|
58
58
|
"@willbooster/web-tree-sitter": "1.0.17",
|
|
59
59
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
package/tree-sitter-tsx.wasm
CHANGED
|
Binary file
|
|
Binary file
|
package/tree-sitter.json
CHANGED
package/tsx/src/node-types.json
CHANGED
|
@@ -97,14 +97,6 @@
|
|
|
97
97
|
"type": "internal_module",
|
|
98
98
|
"named": true
|
|
99
99
|
},
|
|
100
|
-
{
|
|
101
|
-
"type": "jsx_element",
|
|
102
|
-
"named": true
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"type": "jsx_self_closing_element",
|
|
106
|
-
"named": true
|
|
107
|
-
},
|
|
108
100
|
{
|
|
109
101
|
"type": "primary_expression",
|
|
110
102
|
"named": true
|
|
@@ -209,6 +201,14 @@
|
|
|
209
201
|
"type": "identifier",
|
|
210
202
|
"named": true
|
|
211
203
|
},
|
|
204
|
+
{
|
|
205
|
+
"type": "jsx_element",
|
|
206
|
+
"named": true
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"type": "jsx_self_closing_element",
|
|
210
|
+
"named": true
|
|
211
|
+
},
|
|
212
212
|
{
|
|
213
213
|
"type": "member_expression",
|
|
214
214
|
"named": true
|
|
@@ -3146,6 +3146,14 @@
|
|
|
3146
3146
|
"type": "identifier",
|
|
3147
3147
|
"named": true
|
|
3148
3148
|
},
|
|
3149
|
+
{
|
|
3150
|
+
"type": "jsx_element",
|
|
3151
|
+
"named": true
|
|
3152
|
+
},
|
|
3153
|
+
{
|
|
3154
|
+
"type": "jsx_self_closing_element",
|
|
3155
|
+
"named": true
|
|
3156
|
+
},
|
|
3149
3157
|
{
|
|
3150
3158
|
"type": "member_expression",
|
|
3151
3159
|
"named": true
|