@willbooster/tree-sitter-typescript 1.2.14 → 1.3.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.
@@ -19,6 +19,7 @@ const TYPESCRIPT_CONTEXTUAL_KEYWORDS = [
19
19
  'string',
20
20
  'symbol',
21
21
  'object',
22
+ 'out',
22
23
  'new',
23
24
  ];
24
25
 
@@ -121,7 +122,7 @@ module.exports = function defineGrammar(dialect) {
121
122
  [$.type_query, $._type_query_subscript_expression],
122
123
  [$.nested_type_identifier, $.generic_type, $.primary_type, $.lookup_type, $.index_type_query, $.type],
123
124
  // 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],
125
+ [$.nested_identifier, $._in_nested_identifier, $.nested_type_identifier],
125
126
  [$.as_expression, $.satisfies_expression, $.primary_type],
126
127
  [$._type_query_member_expression, $.member_expression],
127
128
  [$.member_expression, $._type_query_member_expression_in_type_annotation],
@@ -192,6 +193,7 @@ module.exports = function defineGrammar(dialect) {
192
193
  ? [[$.primary_type, $.type_parameter]]
193
194
  : [
194
195
  [$.jsx_opening_element, $.type_parameter],
196
+ [$.jsx_opening_element, $.jsx_self_closing_element, $.type_parameter],
195
197
  [$.jsx_namespace_name, $.primary_type],
196
198
  ]),
197
199
  [
@@ -208,6 +210,7 @@ module.exports = function defineGrammar(dialect) {
208
210
  inline: ($, previous) => [
209
211
  ...previous.filter((rule) => !['_formal_parameter', '_call_signature'].includes(rule.name)),
210
212
  $._type_identifier,
213
+ $._type_reference_identifier,
211
214
  $._jsx_start_opening_element,
212
215
  ],
213
216
 
@@ -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('name', choice($.identifier, alias($.nested_identifier, $.member_expression))),
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('name', choice($.string, reserved('properties', $.identifier), $.nested_identifier)),
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: ($) => seq('import', $.identifier, '=', choice($.identifier, $.nested_identifier), $._semicolon),
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(field('module', choice($.identifier, $.nested_identifier)), '.', field('name', $._type_identifier))
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
- $._type_identifier,
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
- $._type_identifier,
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
- optional('const'),
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.2.14",
3
+ "version": "1.3.0",
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.13.1",
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.135.0"
71
+ "wrangler": "4.141.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@willbooster/web-tree-sitter": "^1.0.0"
@@ -33,3 +33,6 @@
33
33
  "override"
34
34
  "satisfies"
35
35
  ] @keyword
36
+
37
+ (type_parameter
38
+ ["in" "out"] @keyword)
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -83,7 +83,7 @@
83
83
  }
84
84
  ],
85
85
  "metadata": {
86
- "version": "1.2.14",
86
+ "version": "1.3.0",
87
87
  "license": "MIT",
88
88
  "description": "TypeScript and TSX grammars for tree-sitter",
89
89
  "authors": [
@@ -6242,6 +6242,10 @@
6242
6242
  "type": "optional_chain",
6243
6243
  "named": true
6244
6244
  },
6245
+ {
6246
+ "type": "out",
6247
+ "named": false
6248
+ },
6245
6249
  {
6246
6250
  "type": "override",
6247
6251
  "named": false
@@ -5992,6 +5992,10 @@
5992
5992
  "type": "optional_chain",
5993
5993
  "named": true
5994
5994
  },
5995
+ {
5996
+ "type": "out",
5997
+ "named": false
5998
+ },
5995
5999
  {
5996
6000
  "type": "override",
5997
6001
  "named": false