@willbooster/tree-sitter-typescript 1.2.14 → 1.3.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/common/defineGrammar.js
CHANGED
|
@@ -3,6 +3,7 @@ const JavaScript = require('@willbooster/tree-sitter-javascript/grammar');
|
|
|
3
3
|
|
|
4
4
|
// Words that are keywords only in some positions and identifiers elsewhere, besides the JavaScript grammar's.
|
|
5
5
|
const TYPESCRIPT_CONTEXTUAL_KEYWORDS = [
|
|
6
|
+
'accessor',
|
|
6
7
|
'declare',
|
|
7
8
|
'global',
|
|
8
9
|
'namespace',
|
|
@@ -19,6 +20,7 @@ const TYPESCRIPT_CONTEXTUAL_KEYWORDS = [
|
|
|
19
20
|
'string',
|
|
20
21
|
'symbol',
|
|
21
22
|
'object',
|
|
23
|
+
'out',
|
|
22
24
|
'new',
|
|
23
25
|
];
|
|
24
26
|
|
|
@@ -121,7 +123,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
121
123
|
[$.type_query, $._type_query_subscript_expression],
|
|
122
124
|
[$.nested_type_identifier, $.generic_type, $.primary_type, $.lookup_type, $.index_type_query, $.type],
|
|
123
125
|
// A qualified type name takes every `.` and name that follow it: `x as a.b.C` is not `(x as a.b).C`.
|
|
124
|
-
[$.nested_identifier, $.nested_type_identifier],
|
|
126
|
+
[$.nested_identifier, $._in_nested_identifier, $.nested_type_identifier],
|
|
125
127
|
[$.as_expression, $.satisfies_expression, $.primary_type],
|
|
126
128
|
[$._type_query_member_expression, $.member_expression],
|
|
127
129
|
[$.member_expression, $._type_query_member_expression_in_type_annotation],
|
|
@@ -192,6 +194,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
192
194
|
? [[$.primary_type, $.type_parameter]]
|
|
193
195
|
: [
|
|
194
196
|
[$.jsx_opening_element, $.type_parameter],
|
|
197
|
+
[$.jsx_opening_element, $.jsx_self_closing_element, $.type_parameter],
|
|
195
198
|
[$.jsx_namespace_name, $.primary_type],
|
|
196
199
|
]),
|
|
197
200
|
[
|
|
@@ -208,13 +211,11 @@ module.exports = function defineGrammar(dialect) {
|
|
|
208
211
|
inline: ($, previous) => [
|
|
209
212
|
...previous.filter((rule) => !['_formal_parameter', '_call_signature'].includes(rule.name)),
|
|
210
213
|
$._type_identifier,
|
|
214
|
+
$._type_reference_identifier,
|
|
211
215
|
$._jsx_start_opening_element,
|
|
212
216
|
],
|
|
213
217
|
|
|
214
218
|
rules: {
|
|
215
|
-
// A field named `get`, `set`, or `static` is told apart from a member that the word modifies by the line-break
|
|
216
|
-
// sentinels allowed right after the name, as in the JavaScript grammar's field_definition. They are not allowed
|
|
217
|
-
// after a type annotation, which may continue on the next line.
|
|
218
219
|
public_field_definition: ($) =>
|
|
219
220
|
seq(
|
|
220
221
|
repeat(field('decorator', $.decorator)),
|
|
@@ -230,7 +231,8 @@ module.exports = function defineGrammar(dialect) {
|
|
|
230
231
|
seq(optional('static'), optional($.override_modifier), optional('readonly')),
|
|
231
232
|
seq(optional('abstract'), optional('readonly')),
|
|
232
233
|
seq(optional('readonly'), optional('abstract')),
|
|
233
|
-
optional('accessor')
|
|
234
|
+
seq(optional('static'), optional($.override_modifier), 'accessor'),
|
|
235
|
+
seq('abstract', optional($.override_modifier), optional('accessor'))
|
|
234
236
|
),
|
|
235
237
|
choice(
|
|
236
238
|
seq(
|
|
@@ -266,7 +268,8 @@ module.exports = function defineGrammar(dialect) {
|
|
|
266
268
|
seq($.override_modifier, optional('readonly')),
|
|
267
269
|
seq('readonly', optional('abstract')),
|
|
268
270
|
seq('abstract', optional('readonly')),
|
|
269
|
-
'accessor'
|
|
271
|
+
seq(optional('static'), optional($.override_modifier), 'accessor'),
|
|
272
|
+
seq('abstract', optional($.override_modifier), optional('accessor'))
|
|
270
273
|
),
|
|
271
274
|
field('name', alias('static', $.property_identifier)),
|
|
272
275
|
choice(
|
|
@@ -413,6 +416,35 @@ module.exports = function defineGrammar(dialect) {
|
|
|
413
416
|
return choice(...choices);
|
|
414
417
|
},
|
|
415
418
|
|
|
419
|
+
_jsx_identifier: ($, previous) => choice(previous, alias(choice('in', 'out'), $.identifier)),
|
|
420
|
+
|
|
421
|
+
nested_identifier: ($) =>
|
|
422
|
+
prec(
|
|
423
|
+
'member',
|
|
424
|
+
seq(
|
|
425
|
+
field(
|
|
426
|
+
'object',
|
|
427
|
+
choice(
|
|
428
|
+
reserved('properties', $.identifier),
|
|
429
|
+
alias('out', $.identifier),
|
|
430
|
+
alias($.nested_identifier, $.member_expression)
|
|
431
|
+
)
|
|
432
|
+
),
|
|
433
|
+
...nestedIdentifierTail($)
|
|
434
|
+
)
|
|
435
|
+
),
|
|
436
|
+
|
|
437
|
+
_in_nested_identifier: ($) =>
|
|
438
|
+
prec(
|
|
439
|
+
'member',
|
|
440
|
+
seq(
|
|
441
|
+
field('object', choice(alias('in', $.identifier), alias($._in_nested_identifier, $.member_expression))),
|
|
442
|
+
...nestedIdentifierTail($)
|
|
443
|
+
)
|
|
444
|
+
),
|
|
445
|
+
|
|
446
|
+
_jsx_element_name: ($, previous) => choice(previous, alias($._in_nested_identifier, $.member_expression)),
|
|
447
|
+
|
|
416
448
|
_jsx_start_opening_element: ($) =>
|
|
417
449
|
seq(
|
|
418
450
|
'<',
|
|
@@ -421,7 +453,14 @@ module.exports = function defineGrammar(dialect) {
|
|
|
421
453
|
choice(
|
|
422
454
|
field('name', choice($._jsx_identifier, $.jsx_namespace_name)),
|
|
423
455
|
seq(
|
|
424
|
-
field(
|
|
456
|
+
field(
|
|
457
|
+
'name',
|
|
458
|
+
choice(
|
|
459
|
+
$._jsx_identifier,
|
|
460
|
+
alias($.nested_identifier, $.member_expression),
|
|
461
|
+
alias($._in_nested_identifier, $.member_expression)
|
|
462
|
+
)
|
|
463
|
+
),
|
|
425
464
|
field('type_arguments', optional($.type_arguments))
|
|
426
465
|
)
|
|
427
466
|
),
|
|
@@ -771,19 +810,41 @@ module.exports = function defineGrammar(dialect) {
|
|
|
771
810
|
_module: ($) =>
|
|
772
811
|
prec.right(
|
|
773
812
|
seq(
|
|
774
|
-
field(
|
|
813
|
+
field(
|
|
814
|
+
'name',
|
|
815
|
+
choice($.string, reserved('properties', $.identifier), alias('out', $.identifier), $.nested_identifier)
|
|
816
|
+
),
|
|
775
817
|
// On .d.ts files "declare module foo" desugars to "declare module foo {}",
|
|
776
818
|
// hence why it is optional here
|
|
777
819
|
field('body', optional($.statement_block))
|
|
778
820
|
)
|
|
779
821
|
),
|
|
780
822
|
|
|
781
|
-
import_alias: ($) =>
|
|
823
|
+
import_alias: ($) =>
|
|
824
|
+
seq(
|
|
825
|
+
'import',
|
|
826
|
+
$.identifier,
|
|
827
|
+
'=',
|
|
828
|
+
choice($.identifier, alias('out', $.identifier), $.nested_identifier),
|
|
829
|
+
$._semicolon
|
|
830
|
+
),
|
|
782
831
|
|
|
783
832
|
nested_type_identifier: ($) =>
|
|
784
833
|
prec(
|
|
785
834
|
'member',
|
|
786
|
-
seq(
|
|
835
|
+
seq(
|
|
836
|
+
field(
|
|
837
|
+
'module',
|
|
838
|
+
choice(
|
|
839
|
+
$.identifier,
|
|
840
|
+
alias(choice('in', 'out'), $.identifier),
|
|
841
|
+
$.nested_identifier,
|
|
842
|
+
alias($._in_nested_identifier, $.nested_identifier)
|
|
843
|
+
)
|
|
844
|
+
),
|
|
845
|
+
'.',
|
|
846
|
+
field('name', $._type_reference_identifier)
|
|
847
|
+
)
|
|
787
848
|
),
|
|
788
849
|
|
|
789
850
|
interface_declaration: ($) =>
|
|
@@ -874,7 +935,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
874
935
|
field('arguments', $.arguments)
|
|
875
936
|
),
|
|
876
937
|
|
|
877
|
-
asserts: ($) => seq('asserts', choice($.type_predicate, $.identifier, $.this)),
|
|
938
|
+
asserts: ($) => seq('asserts', choice($.type_predicate, $.identifier, alias('out', $.identifier), $.this)),
|
|
878
939
|
|
|
879
940
|
asserts_annotation: ($) => seq(seq(':', $.asserts)),
|
|
880
941
|
|
|
@@ -897,11 +958,8 @@ module.exports = function defineGrammar(dialect) {
|
|
|
897
958
|
|
|
898
959
|
optional_tuple_parameter: ($) => seq(field('name', $._tuple_label), '?', field('type', $.type_annotation)),
|
|
899
960
|
|
|
900
|
-
_tuple_rest_label: ($) => seq('...', $._tuple_label),
|
|
961
|
+
_tuple_rest_label: ($) => seq('...', choice($._tuple_label, alias('in', $.identifier))),
|
|
901
962
|
|
|
902
|
-
// TypeScript accepts any identifier name as a tuple label, but where a tuple member begins, the keywords that
|
|
903
|
-
// can begin a type are lexed as those keywords, so they are listed here. Keywords that are rules of their own
|
|
904
|
-
// are aliased as rules: repeating their strings would turn those rules into nodes that wrap a token.
|
|
905
963
|
_tuple_label: ($) =>
|
|
906
964
|
choice(
|
|
907
965
|
$.identifier,
|
|
@@ -917,6 +975,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
917
975
|
'never',
|
|
918
976
|
'object',
|
|
919
977
|
'readonly',
|
|
978
|
+
'out',
|
|
920
979
|
'keyof',
|
|
921
980
|
'infer',
|
|
922
981
|
'typeof',
|
|
@@ -960,7 +1019,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
960
1019
|
choice(
|
|
961
1020
|
$.parenthesized_type,
|
|
962
1021
|
$.predefined_type,
|
|
963
|
-
$.
|
|
1022
|
+
$._type_reference_identifier,
|
|
964
1023
|
$.nested_type_identifier,
|
|
965
1024
|
$.generic_type,
|
|
966
1025
|
$.object_type,
|
|
@@ -1007,7 +1066,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
1007
1066
|
field(
|
|
1008
1067
|
'name',
|
|
1009
1068
|
choice(
|
|
1010
|
-
$.
|
|
1069
|
+
$._type_reference_identifier,
|
|
1011
1070
|
$.nested_type_identifier,
|
|
1012
1071
|
alias($._type_query_member_expression_in_type_annotation, $.member_expression)
|
|
1013
1072
|
)
|
|
@@ -1022,6 +1081,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
1022
1081
|
'name',
|
|
1023
1082
|
choice(
|
|
1024
1083
|
$.identifier,
|
|
1084
|
+
alias('out', $.identifier),
|
|
1025
1085
|
$.this,
|
|
1026
1086
|
// Sometimes tree-sitter contextual lexing is not good enough to know
|
|
1027
1087
|
// that 'object' in ':object is foo' is really an identifier and not
|
|
@@ -1201,7 +1261,7 @@ module.exports = function defineGrammar(dialect) {
|
|
|
1201
1261
|
|
|
1202
1262
|
type_parameter: ($) =>
|
|
1203
1263
|
seq(
|
|
1204
|
-
|
|
1264
|
+
repeat(choice('const', 'in', 'out')),
|
|
1205
1265
|
field('name', $._type_identifier),
|
|
1206
1266
|
field('constraint', optional($.constraint)),
|
|
1207
1267
|
field('value', optional($.default_type))
|
|
@@ -1264,13 +1324,28 @@ module.exports = function defineGrammar(dialect) {
|
|
|
1264
1324
|
|
|
1265
1325
|
// A type name may be a reserved word, which TypeScript reports only as a semantic error. The reserved words must be
|
|
1266
1326
|
// allowed on the identifier inside the alias: around the alias, the keyword token still wins in the lexer.
|
|
1267
|
-
_type_identifier: ($) => alias(reserved('properties', $.identifier), $.type_identifier),
|
|
1327
|
+
_type_identifier: ($) => alias(choice(reserved('properties', $.identifier), 'out'), $.type_identifier),
|
|
1328
|
+
|
|
1329
|
+
_type_reference_identifier: ($) => choice($._type_identifier, alias('in', $.type_identifier)),
|
|
1268
1330
|
|
|
1269
1331
|
_reserved_identifier: (_, previous) => choice(...TYPESCRIPT_CONTEXTUAL_KEYWORDS, previous),
|
|
1270
1332
|
},
|
|
1271
1333
|
});
|
|
1272
1334
|
};
|
|
1273
1335
|
|
|
1336
|
+
function nestedIdentifierTail($) {
|
|
1337
|
+
return [
|
|
1338
|
+
'.',
|
|
1339
|
+
field(
|
|
1340
|
+
'property',
|
|
1341
|
+
choice(
|
|
1342
|
+
reserved('properties', alias($.identifier, $.property_identifier)),
|
|
1343
|
+
alias(choice('in', 'out'), $.property_identifier)
|
|
1344
|
+
)
|
|
1345
|
+
),
|
|
1346
|
+
];
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1274
1349
|
/**
|
|
1275
1350
|
* Creates a rule to match one or more of the rules separated by a comma
|
|
1276
1351
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-typescript",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "TypeScript and TSX grammars for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
55
55
|
"@willbooster/oxlint-config": "1.4.8",
|
|
56
56
|
"@willbooster/tree-sitter-javascript": "1.0.21",
|
|
57
|
-
"@willbooster/wb": "22.
|
|
57
|
+
"@willbooster/wb": "22.18.0",
|
|
58
58
|
"@willbooster/web-tree-sitter": "1.0.17",
|
|
59
59
|
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
60
60
|
"lefthook": "2.1.14",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript-reference": "npm:typescript@5.9.3",
|
|
69
69
|
"vite": "8.3.0",
|
|
70
70
|
"vitest": "5.0.2",
|
|
71
|
-
"wrangler": "4.
|
|
71
|
+
"wrangler": "4.141.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@willbooster/web-tree-sitter": "^1.0.0"
|
package/queries/highlights.scm
CHANGED
package/tree-sitter-tsx.wasm
CHANGED
|
Binary file
|
|
Binary file
|
package/tree-sitter.json
CHANGED
package/tsx/src/node-types.json
CHANGED