pub(super) fn compress_tpl(&mut self, tpl: &mut Tpl) {
        debug_assert_eq!(tpl.exprs.len() + 1, tpl.quasis.len());
        let has_str_lit = tpl.exprs.iter().any(|expr| match &**expr {
            Expr::Lit(Lit::Str(..)) => true,
            _ => false,
        });
        if !has_str_lit {
            return;
        }

        if cfg!(feature = "debug") {
            tracing::debug!("compress_tpl");
        }

        let mut quasis = vec![];
        let mut exprs = vec![];
        let mut cur_raw = String::new();

        for i in 0..(tpl.exprs.len() + tpl.quasis.len()) {
            if i % 2 == 0 {
                let i = i / 2;
                let q = tpl.quasis[i].take();

                cur_raw.push_str(&q.raw.value);
            } else {
                let i = i / 2;
                let e = tpl.exprs[i].take();

                match *e {
                    Expr::Lit(Lit::Str(s)) => {
                        cur_raw.push_str(&s.value);
                    }
                    _ => {
                        quasis.push(TplElement {
                            span: DUMMY_SP,
                            tail: true,
                            cooked: None,
                            raw: Str {
                                span: DUMMY_SP,
                                value: take(&mut cur_raw).into(),
                                has_escape: false,
                                kind: Default::default(),
                            },
                        });

                        exprs.push(e);
                    }
                }
            }
        }

        quasis.push(TplElement {
            span: DUMMY_SP,
            tail: true,
            cooked: None,
            raw: Str {
                span: DUMMY_SP,
                value: cur_raw.into(),
                has_escape: false,
                kind: Default::default(),
            },
        });

        debug_assert_eq!(exprs.len() + 1, quasis.len());

        tpl.quasis = quasis;
        tpl.exprs = exprs;
    }
/// This compresses a template literal by inlining string literals in
/// expresions into quasis.
///
/// Note that this pass only cares about string literals and conversion to a
/// string literal should be done before calling this pass.
This compresses a template literal by inlining string literals in
expresions into quasis.

Note that this pass only cares about string literals and conversion to a
string literal should be done before calling this pass.
This compresses a template literal by inlining string literals in expresions into quasis . Note that this pass only cares about string literals and conversion to a string literal should be done before calling this pass .
pub(super) fn compress_tpl(&mut self, tpl: &mut Tpl) {
        debug_assert_eq!(tpl.exprs.len() + 1, tpl.quasis.len());
        let has_str_lit = tpl.exprs.iter().any(|expr| match &**expr {
            Expr::Lit(Lit::Str(..)) => true,
            _ => false,
        });
        if !has_str_lit {
            return;
        }
        if cfg!(feature = "debug") {
            tracing::debug!("compress_tpl");
        }
        let mut quasis = vec![];
        let mut exprs = vec![];
        let mut cur_raw = String::new();
        for i in 0..(tpl.exprs.len() + tpl.quasis.len()) {
            if i % 2 == 0 {
                let i = i / 2;
                let q = tpl.quasis[i].take();
                cur_raw.push_str(&q.raw.value);
            } else {
                let i = i / 2;
                let e = tpl.exprs[i].take();
                match *e {
                    Expr::Lit(Lit::Str(s)) => {
                        cur_raw.push_str(&s.value);
                    }
                    _ => {
                        quasis.push(TplElement {
                            span: DUMMY_SP,
                            tail: true,
                            cooked: None,
                            raw: Str {
                                span: DUMMY_SP,
                                value: take(&mut cur_raw).into(),
                                has_escape: false,
                                kind: Default::default(),
                            },
                        });
                        exprs.push(e);
                    }
                }
            }
        }
        quasis.push(TplElement {
            span: DUMMY_SP,
            tail: true,
            cooked: None,
            raw: Str {
                span: DUMMY_SP,
                value: cur_raw.into(),
                has_escape: false,
                kind: Default::default(),
            },
        });
        debug_assert_eq!(exprs.len() + 1, quasis.len());
        tpl.quasis = quasis;
        tpl.exprs = exprs;
    }
pub ( super ) fn compress_tpl ( & mut self , tpl : & mut Tpl ) { debug_assert_eq ! ( tpl exprs len ( ) 1 tpl quasis len ( ) ) ; let has_str_lit = tpl . exprs . iter ( ) . any ( | expr | match & * * expr { Expr :: Lit ( Lit :: Str ( .. ) ) => true , _ => false , } ) ; if ! has_str_lit { return ; } if cfg ! ( feature " " ) { tracing :: debug ! ( " " ) ; } let mut quasis = vec ! [ ] ; let mut exprs = vec ! [ ] ; let mut cur_raw = String :: new ( ) ; for i in 0 .. ( tpl . exprs . len ( ) + tpl . quasis . len ( ) ) { if i % 2 == 0 { let i = i / 2 ; let q = tpl . quasis [ i ] . take ( ) ; cur_raw . push_str ( & q . raw . value ) ; } else { let i = i / 2 ; let e = tpl . exprs [ i ] . take ( ) ; match * e { Expr :: Lit ( Lit :: Str ( s ) ) => { cur_raw . push_str ( & s . value ) ; } _ => { quasis . push ( TplElement { span : DUMMY_SP , tail : true , cooked : None , raw : Str { span : DUMMY_SP , value : take ( & mut cur_raw ) . into ( ) , has_escape : false , kind : Default :: default ( ) , } , } ) ; exprs . push ( e ) ; } } } } quasis . push ( TplElement { span : DUMMY_SP , tail : true , cooked : None , raw : Str { span : DUMMY_SP , value : cur_raw . into ( ) , has_escape : false , kind : Default :: default ( ) , } , } ) ; debug_assert_eq ! ( exprs len ( ) 1 quasis len ( ) ) ; tpl . quasis = quasis ; tpl . exprs = exprs ; }
This compresses a template literal by inlining string literals in
expresions into quasis.
This compresses a template literal by inlining string literals in expresions into quasis .
&mut self
tpl
&mut Tpl