@@ -3016,13 +3016,13 @@ fn gen_spread_element<'a>(node: &SpreadElement<'a>, context: &mut Context<'a>) -
3016
3016
/// Detects the type of embedded language automatically.
3017
3017
fn maybe_gen_tagged_tpl_with_external_formatter < ' a > ( node : & TaggedTpl < ' a > , context : & mut Context < ' a > ) -> Option < PrintItems > {
3018
3018
let external_formatter = context. external_formatter . as_ref ( ) ?;
3019
- let media_type = detect_embedded_language_type ( node) ?;
3019
+ let embedded_lang = normalize_embedded_language_type ( node) ?;
3020
3020
3021
3021
let placeholder_css = "@dpr1nt_" ;
3022
3022
let placeholder_other = "dpr1nt_" ;
3023
3023
// First creates text with placeholders for the expressions.
3024
- let placeholder_text = match media_type {
3025
- MediaType :: Css => placeholder_css,
3024
+ let placeholder_text = match embedded_lang {
3025
+ "css" => placeholder_css,
3026
3026
_ => placeholder_other,
3027
3027
} ;
3028
3028
let text = capacity_builder:: StringBuilder :: < String > :: build ( |builder| {
@@ -3043,7 +3043,7 @@ fn maybe_gen_tagged_tpl_with_external_formatter<'a>(node: &TaggedTpl<'a>, contex
3043
3043
. unwrap ( ) ;
3044
3044
3045
3045
// Then formats the text with the external formatter.
3046
- let formatted_tpl = match external_formatter ( media_type , text. replace ( r"\\" , "\\ " ) , context. config ) {
3046
+ let formatted_tpl = match external_formatter ( embedded_lang , text. replace ( r"\\" , "\\ " ) , context. config ) {
3047
3047
Ok ( formatted_tpl) => formatted_tpl?. replace ( "\\ " , r"\\" ) ,
3048
3048
Err ( err) => {
3049
3049
context. diagnostics . push ( context:: GenerateDiagnostic {
@@ -3102,29 +3102,22 @@ fn maybe_gen_tagged_tpl_with_external_formatter<'a>(node: &TaggedTpl<'a>, contex
3102
3102
Some ( items)
3103
3103
}
3104
3104
3105
- /// Detects the type of embedded language in a tagged template literal.
3106
- fn detect_embedded_language_type < ' a > ( node : & TaggedTpl < ' a > ) -> Option < MediaType > {
3105
+ /// Normalizes the type of embedded language in a tagged template literal.
3106
+ fn normalize_embedded_language_type < ' a > ( node : & TaggedTpl < ' a > ) -> Option < & ' a str > {
3107
3107
match node. tag {
3108
- Expr :: Ident ( ident) => {
3109
- match ident. sym ( ) . as_str ( ) {
3110
- "css" => Some ( MediaType :: Css ) , // css`...`
3111
- "html" => Some ( MediaType :: Html ) , // html`...`
3112
- "sql" => Some ( MediaType :: Sql ) , // sql`...`
3113
- _ => None ,
3114
- }
3115
- }
3108
+ Expr :: Ident ( ident) => return Some ( ident. sym ( ) . as_str ( ) ) ,
3116
3109
Expr :: Member ( member_expr) => {
3117
3110
if let Expr :: Ident ( ident) = member_expr. obj {
3118
3111
if ident. sym ( ) . as_str ( ) == "styled" {
3119
- return Some ( MediaType :: Css ) ; // styled.foo`...`
3112
+ return Some ( "css" ) ; // styled.foo`...`
3120
3113
}
3121
3114
}
3122
3115
None
3123
3116
}
3124
3117
Expr :: Call ( call_expr) => {
3125
3118
if let Callee :: Expr ( Expr :: Ident ( ident) ) = call_expr. callee {
3126
3119
if ident. sym ( ) . as_str ( ) == "styled" {
3127
- return Some ( MediaType :: Css ) ; // styled(Button)`...`
3120
+ return Some ( "css" ) ; // styled(Button)`...`
3128
3121
}
3129
3122
}
3130
3123
None
0 commit comments