Skip to content

Commit dfaf3d1

Browse files
committed
Add intersection/union types to _primary_type
1 parent 111b077 commit dfaf3d1

File tree

9 files changed

+218358
-218221
lines changed

9 files changed

+218358
-218221
lines changed

common/corpus/types.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ type A<B, C> = B extends C
11021102
: never
11031103
: never
11041104
type Trim<S extends string> = S extends `${infer R}` ? Trim<R> : S;
1105+
type A = `${true & ('foo' | false)}`;
11051106
---
11061107
(program
11071108
(type_alias_declaration
@@ -1189,7 +1190,22 @@ type Trim<S extends string> = S extends `${infer R}` ? Trim<R> : S;
11891190
(type_identifier)
11901191
(type_arguments
11911192
(type_identifier)))
1192-
(type_identifier))))
1193+
(type_identifier)))
1194+
(type_alias_declaration
1195+
(type_identifier)
1196+
(template_literal_type
1197+
(template_type
1198+
(intersection_type
1199+
(literal_type
1200+
(true))
1201+
(parenthesized_type
1202+
(union_type
1203+
(literal_type
1204+
(string
1205+
(string_fragment)))
1206+
(literal_type
1207+
(false)))))))))
1208+
11931209
==================================
11941210
Mapped type 'as' clauses
11951211
==================================

common/define-grammar.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,14 @@ module.exports = function defineGrammar(dialect) {
642642
$.literal_type,
643643
$.lookup_type,
644644
$.conditional_type,
645-
$.template_literal_type
645+
$.template_literal_type,
646+
$.intersection_type,
647+
$.union_type
646648
),
647649

648-
template_type: $ => seq('${',choice($._primary_type, $.infer_type),'}'),
650+
template_type: $ => seq('${', choice($._primary_type, $.infer_type), '}'),
649651

650-
template_literal_type: $ => seq(
652+
template_literal_type: $ => seq(
651653
'`',
652654
repeat(choice(
653655
$._template_chars,

tsx/src/grammar.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8613,6 +8613,14 @@
86138613
{
86148614
"type": "SYMBOL",
86158615
"name": "template_literal_type"
8616+
},
8617+
{
8618+
"type": "SYMBOL",
8619+
"name": "intersection_type"
8620+
},
8621+
{
8622+
"type": "SYMBOL",
8623+
"name": "union_type"
86168624
}
86178625
]
86188626
},

0 commit comments

Comments
 (0)