Skip to content

Commit 54931b3

Browse files
authored
Merge pull request #201 from kraftwerk28/fix-template-literal-type
Add intersection/union types to `_primary_type`
2 parents 111b077 + d863bcb commit 54931b3

File tree

9 files changed

+168758
-169166
lines changed

9 files changed

+168758
-169166
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,6 @@ module.exports = function defineGrammar(dialect) {
587587

588588
_type: $ => choice(
589589
$._primary_type,
590-
$.union_type,
591-
$.intersection_type,
592590
$.function_type,
593591
$.readonly_type,
594592
$.constructor_type,
@@ -642,12 +640,14 @@ module.exports = function defineGrammar(dialect) {
642640
$.literal_type,
643641
$.lookup_type,
644642
$.conditional_type,
645-
$.template_literal_type
643+
$.template_literal_type,
644+
$.intersection_type,
645+
$.union_type
646646
),
647647

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

650-
template_literal_type: $ => seq(
650+
template_literal_type: $ => seq(
651651
'`',
652652
repeat(choice(
653653
$._template_chars,

tsx/src/grammar.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8347,14 +8347,6 @@
83478347
"type": "SYMBOL",
83488348
"name": "_primary_type"
83498349
},
8350-
{
8351-
"type": "SYMBOL",
8352-
"name": "union_type"
8353-
},
8354-
{
8355-
"type": "SYMBOL",
8356-
"name": "intersection_type"
8357-
},
83588350
{
83598351
"type": "SYMBOL",
83608352
"name": "function_type"
@@ -8613,6 +8605,14 @@
86138605
{
86148606
"type": "SYMBOL",
86158607
"name": "template_literal_type"
8608+
},
8609+
{
8610+
"type": "SYMBOL",
8611+
"name": "intersection_type"
8612+
},
8613+
{
8614+
"type": "SYMBOL",
8615+
"name": "union_type"
86168616
}
86178617
]
86188618
},

0 commit comments

Comments
 (0)