@@ -380,11 +380,13 @@ impl<'a> ParserImpl<'a> {
380380 // return parseJSDocFunctionType();
381381 Kind :: Question => self . parse_js_doc_unknown_or_nullable_type ( ) ,
382382 Kind :: Bang => self . parse_js_doc_non_nullable_type ( ) ,
383- Kind :: NoSubstitutionTemplate | Kind :: Str | Kind :: True | Kind :: False => {
384- self . parse_literal_type_node ( /* negative */ false )
385- }
386- kind if kind. is_number ( ) => {
387- self . parse_literal_type_node ( /* negative */ false )
383+ Kind :: Str | Kind :: True | Kind :: False => self . parse_literal_type ( ) ,
384+ kind if kind. is_number ( ) => self . parse_literal_type ( ) ,
385+ Kind :: NoSubstitutionTemplate => {
386+ let span = self . start_span ( ) ;
387+ let literal = self . parse_template_literal ( false ) ;
388+ let span = self . end_span ( span) ;
389+ self . ast . ts_type_literal_type ( span, TSLiteral :: TemplateLiteral ( self . alloc ( literal) ) )
388390 }
389391 Kind :: Minus => {
390392 let checkpoint = self . checkpoint ( ) ;
@@ -393,7 +395,7 @@ impl<'a> ParserImpl<'a> {
393395 self . bump_any ( ) ; // bump `-`
394396
395397 if self . cur_kind ( ) . is_number ( ) {
396- self . parse_rest_of_literal_type_node ( minus_start_span, /* negative */ true )
398+ self . parse_literal_type_negative ( minus_start_span)
397399 } else {
398400 self . rewind ( checkpoint) ;
399401 self . parse_type_reference ( )
@@ -984,39 +986,28 @@ impl<'a> ParserImpl<'a> {
984986 }
985987 }
986988
987- fn parse_literal_type_node ( & mut self , negative : bool ) -> TSType < ' a > {
989+ fn parse_literal_type ( & mut self ) -> TSType < ' a > {
988990 let span = self . start_span ( ) ;
989- if negative {
990- self . bump_any ( ) ; // bump `-`
991- }
992-
993- self . parse_rest_of_literal_type_node ( span, negative)
994- }
995-
996- fn parse_rest_of_literal_type_node ( & mut self , span : u32 , negative : bool ) -> TSType < ' a > {
997- let expression = if self . at ( Kind :: NoSubstitutionTemplate ) {
998- self . parse_template_literal_expression ( false )
999- } else {
1000- self . parse_literal_expression ( )
1001- } ;
1002-
991+ let expression = self . parse_literal_expression ( ) ;
1003992 let span = self . end_span ( span) ;
1004- let literal = if negative {
1005- match self . ast . expression_unary ( span, UnaryOperator :: UnaryNegation , expression) {
1006- Expression :: UnaryExpression ( unary_expr) => TSLiteral :: UnaryExpression ( unary_expr) ,
1007- _ => unreachable ! ( ) ,
1008- }
1009- } else {
1010- match expression {
1011- Expression :: BooleanLiteral ( literal) => TSLiteral :: BooleanLiteral ( literal) ,
1012- Expression :: NumericLiteral ( literal) => TSLiteral :: NumericLiteral ( literal) ,
1013- Expression :: BigIntLiteral ( literal) => TSLiteral :: BigIntLiteral ( literal) ,
1014- Expression :: StringLiteral ( literal) => TSLiteral :: StringLiteral ( literal) ,
1015- Expression :: TemplateLiteral ( literal) => TSLiteral :: TemplateLiteral ( literal) ,
1016- _ => return self . unexpected ( ) ,
1017- }
993+ let literal = match expression {
994+ Expression :: BooleanLiteral ( literal) => TSLiteral :: BooleanLiteral ( literal) ,
995+ Expression :: NumericLiteral ( literal) => TSLiteral :: NumericLiteral ( literal) ,
996+ Expression :: BigIntLiteral ( literal) => TSLiteral :: BigIntLiteral ( literal) ,
997+ Expression :: StringLiteral ( literal) => TSLiteral :: StringLiteral ( literal) ,
998+ _ => return self . unexpected ( ) ,
1018999 } ;
1000+ self . ast . ts_type_literal_type ( span, literal)
1001+ }
10191002
1003+ fn parse_literal_type_negative ( & mut self , span : u32 ) -> TSType < ' a > {
1004+ let literal_expr = self . parse_literal_expression ( ) ;
1005+ let span = self . end_span ( span) ;
1006+ let literal = TSLiteral :: UnaryExpression ( self . ast . alloc_unary_expression (
1007+ span,
1008+ UnaryOperator :: UnaryNegation ,
1009+ literal_expr,
1010+ ) ) ;
10201011 self . ast . ts_type_literal_type ( span, literal)
10211012 }
10221013
0 commit comments