Skip to content

Commit 0ae3828

Browse files
Merge pull request #228 from Shraymonks/satisfies
Support satisfies operator
2 parents 0ab9d99 + 163b395 commit 0ae3828

File tree

10 files changed

+245706
-237183
lines changed

10 files changed

+245706
-237183
lines changed

common/corpus/declarations.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,17 @@ Type casts
456456
=================================
457457

458458
foo as any as Array<number>
459+
bar satisfies number[]
459460

460461
---
461462

462463
(program
463464
(expression_statement
464465
(as_expression
465466
(as_expression (identifier) (predefined_type))
466-
(generic_type (type_identifier) (type_arguments (predefined_type))))))
467+
(generic_type (type_identifier) (type_arguments (predefined_type)))))
468+
(expression_statement
469+
(satisfies_expression (identifier) (array_type (predefined_type)))))
467470

468471
=================================
469472
Ambient export function declarations

common/corpus/expressions.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,45 @@ T as {} & { [t: T]: T } & { [g: G]: G }
3737
(type_identifier)
3838
(type_annotation (type_identifier))))))))
3939

40+
==================================
41+
Satisfies expressions
42+
==================================
43+
44+
h satisfies `hello`
45+
T satisfies {} & { [t: T]: T }
46+
T satisfies {} & { [t: T]: T } & { [g: G]: G }
47+
48+
---
49+
50+
(program
51+
(expression_statement (satisfies_expression (identifier) (template_literal_type)))
52+
(expression_statement
53+
(satisfies_expression
54+
(identifier)
55+
(intersection_type
56+
(object_type)
57+
(object_type
58+
(index_signature
59+
(identifier)
60+
(type_identifier)
61+
(type_annotation (type_identifier)))))))
62+
(expression_statement
63+
(satisfies_expression
64+
(identifier)
65+
(intersection_type
66+
(intersection_type
67+
(object_type)
68+
(object_type
69+
(index_signature
70+
(identifier)
71+
(type_identifier)
72+
(type_annotation (type_identifier)))))
73+
(object_type
74+
(index_signature
75+
(identifier)
76+
(type_identifier)
77+
(type_annotation (type_identifier))))))))
78+
4079
==================================
4180
Typeof expressions
4281
==================================

common/define-grammar.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function defineGrammar(dialect) {
2020
[
2121
'call',
2222
'unary',
23-
'binary_as',
23+
'binary',
2424
$.await_expression,
2525
$.arrow_function,
2626
],
@@ -29,7 +29,7 @@ module.exports = function defineGrammar(dialect) {
2929
$.union_type,
3030
$.conditional_type,
3131
$.function_type,
32-
'binary_as',
32+
'binary',
3333
$.type_predicate,
3434
$.readonly_type
3535
],
@@ -47,7 +47,7 @@ module.exports = function defineGrammar(dialect) {
4747
[$.type_query, $.subscript_expression, $.expression],
4848
[$.type_query, $._type_query_subscript_expression],
4949
[$.nested_type_identifier, $.generic_type, $._primary_type, $.lookup_type, $.index_type_query, $._type],
50-
[$.as_expression, $._primary_type],
50+
[$.as_expression, $.satisfies_expression, $._primary_type],
5151
[$._type_query_member_expression, $.member_expression],
5252
[$._type_query_member_expression, $.primary_expression],
5353
[$._type_query_subscript_expression, $.subscript_expression],
@@ -208,6 +208,7 @@ module.exports = function defineGrammar(dialect) {
208208
expression: ($, previous) => {
209209
const choices = [
210210
$.as_expression,
211+
$.satisfies_expression,
211212
$.internal_module,
212213
];
213214

@@ -403,10 +404,16 @@ module.exports = function defineGrammar(dialect) {
403404
$.expression
404405
)),
405406

406-
as_expression: $ => prec.left('binary_as', seq(
407+
as_expression: $ => prec.left('binary', seq(
407408
$.expression,
408409
'as',
409-
choice($._type, $.template_literal_type)
410+
$._type
411+
)),
412+
413+
satisfies_expression: $ => prec.left('binary', seq(
414+
$.expression,
415+
'satisfies',
416+
$._type
410417
)),
411418

412419
class_heritage: $ => choice(

queries/highlights.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
"type"
3232
"readonly"
3333
"override"
34+
"satisfies"
3435
] @keyword

tsx/src/grammar.json

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,10 @@
19001900
"type": "SYMBOL",
19011901
"name": "as_expression"
19021902
},
1903+
{
1904+
"type": "SYMBOL",
1905+
"name": "satisfies_expression"
1906+
},
19031907
{
19041908
"type": "SYMBOL",
19051909
"name": "internal_module"
@@ -7442,7 +7446,7 @@
74427446
},
74437447
"as_expression": {
74447448
"type": "PREC_LEFT",
7445-
"value": "binary_as",
7449+
"value": "binary",
74467450
"content": {
74477451
"type": "SEQ",
74487452
"members": [
@@ -7455,17 +7459,29 @@
74557459
"value": "as"
74567460
},
74577461
{
7458-
"type": "CHOICE",
7459-
"members": [
7460-
{
7461-
"type": "SYMBOL",
7462-
"name": "_type"
7463-
},
7464-
{
7465-
"type": "SYMBOL",
7466-
"name": "template_literal_type"
7467-
}
7468-
]
7462+
"type": "SYMBOL",
7463+
"name": "_type"
7464+
}
7465+
]
7466+
}
7467+
},
7468+
"satisfies_expression": {
7469+
"type": "PREC_LEFT",
7470+
"value": "binary",
7471+
"content": {
7472+
"type": "SEQ",
7473+
"members": [
7474+
{
7475+
"type": "SYMBOL",
7476+
"name": "expression"
7477+
},
7478+
{
7479+
"type": "STRING",
7480+
"value": "satisfies"
7481+
},
7482+
{
7483+
"type": "SYMBOL",
7484+
"name": "_type"
74697485
}
74707486
]
74717487
}
@@ -10746,7 +10762,7 @@
1074610762
},
1074710763
{
1074810764
"type": "STRING",
10749-
"value": "binary_as"
10765+
"value": "binary"
1075010766
},
1075110767
{
1075210768
"type": "SYMBOL",
@@ -10776,7 +10792,7 @@
1077610792
},
1077710793
{
1077810794
"type": "STRING",
10779-
"value": "binary_as"
10795+
"value": "binary"
1078010796
},
1078110797
{
1078210798
"type": "SYMBOL",
@@ -10960,6 +10976,10 @@
1096010976
"type": "SYMBOL",
1096110977
"name": "as_expression"
1096210978
},
10979+
{
10980+
"type": "SYMBOL",
10981+
"name": "satisfies_expression"
10982+
},
1096310983
{
1096410984
"type": "SYMBOL",
1096510985
"name": "_primary_type"

tsx/src/node-types.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@
195195
"type": "primary_expression",
196196
"named": true
197197
},
198+
{
199+
"type": "satisfies_expression",
200+
"named": true
201+
},
198202
{
199203
"type": "ternary_expression",
200204
"named": true
@@ -4899,6 +4903,41 @@
48994903
]
49004904
}
49014905
},
4906+
{
4907+
"type": "satisfies_expression",
4908+
"named": true,
4909+
"fields": {},
4910+
"children": {
4911+
"multiple": true,
4912+
"required": true,
4913+
"types": [
4914+
{
4915+
"type": "_primary_type",
4916+
"named": true
4917+
},
4918+
{
4919+
"type": "constructor_type",
4920+
"named": true
4921+
},
4922+
{
4923+
"type": "expression",
4924+
"named": true
4925+
},
4926+
{
4927+
"type": "function_type",
4928+
"named": true
4929+
},
4930+
{
4931+
"type": "infer_type",
4932+
"named": true
4933+
},
4934+
{
4935+
"type": "readonly_type",
4936+
"named": true
4937+
}
4938+
]
4939+
}
4940+
},
49024941
{
49034942
"type": "sequence_expression",
49044943
"named": true,
@@ -6313,6 +6352,10 @@
63136352
"type": "return",
63146353
"named": false
63156354
},
6355+
{
6356+
"type": "satisfies",
6357+
"named": false
6358+
},
63166359
{
63176360
"type": "set",
63186361
"named": false

0 commit comments

Comments
 (0)