@@ -451,13 +451,16 @@ impl<'a> ParserImpl<'a> {
451451 /// `SubstitutionTemplate`[?Yield, ?Await, ?Tagged]
452452 pub ( crate ) fn parse_template_literal ( & mut self , tagged : bool ) -> TemplateLiteral < ' a > {
453453 let span = self . start_span ( ) ;
454- let mut expressions = self . ast . vec ( ) ;
455- let mut quasis = self . ast . vec ( ) ;
456- match self . cur_kind ( ) {
454+
455+ let ( quasis, expressions) = match self . cur_kind ( ) {
457456 Kind :: NoSubstitutionTemplate => {
458- quasis. push ( self . parse_template_element ( tagged) ) ;
457+ let quasis = self . ast . vec1 ( self . parse_template_element ( tagged) ) ;
458+ ( quasis, self . ast . vec ( ) )
459459 }
460460 Kind :: TemplateHead => {
461+ let mut expressions = self . ast . vec_with_capacity ( 1 ) ;
462+ let mut quasis = self . ast . vec_with_capacity ( 2 ) ;
463+
461464 quasis. push ( self . parse_template_element ( tagged) ) ;
462465 // TemplateHead Expression[+In, ?Yield, ?Await]
463466 let expr = self . context ( Context :: In , Context :: empty ( ) , Self :: parse_expr) ;
@@ -483,9 +486,12 @@ impl<'a> ParserImpl<'a> {
483486 }
484487 }
485488 }
489+
490+ ( quasis, expressions)
486491 }
487492 _ => unreachable ! ( "parse_template_literal" ) ,
488- }
493+ } ;
494+
489495 self . ast . template_literal ( self . end_span ( span) , quasis, expressions)
490496 }
491497
0 commit comments