@@ -3992,22 +3992,22 @@ mod string_literal {
3992
3992
use super :: * ;
3993
3993
3994
3994
pub fn gen_non_jsx_text ( string_value : & str , context : & mut Context ) -> PrintItems {
3995
- gen_from_raw_string ( & match context. config . quote_style {
3995
+ match context. config . quote_style {
3996
3996
QuoteStyle :: AlwaysDouble => format_with_double ( string_value) ,
3997
3997
QuoteStyle :: AlwaysSingle => format_with_single ( string_value) ,
3998
3998
QuoteStyle :: PreferDouble => handle_prefer_double ( string_value) ,
3999
3999
QuoteStyle :: PreferSingle => handle_prefer_single ( string_value) ,
4000
- } )
4000
+ }
4001
4001
}
4002
4002
4003
4003
pub fn gen_jsx_text ( string_value : & str , context : & mut Context ) -> PrintItems {
4004
4004
// JSX attributes cannot contain escaped quotes so regardless of
4005
4005
// configuration, allow changing the quote style to single or
4006
4006
// double depending on if it contains the opposite quote
4007
- gen_from_raw_string ( & match context. config . jsx_quote_style {
4007
+ match context. config . jsx_quote_style {
4008
4008
JsxQuoteStyle :: PreferDouble => handle_prefer_double ( string_value) ,
4009
4009
JsxQuoteStyle :: PreferSingle => handle_prefer_single ( string_value) ,
4010
- } )
4010
+ }
4011
4011
}
4012
4012
4013
4013
pub fn get_value ( node : & Str , context : & mut Context ) -> String {
@@ -4049,28 +4049,36 @@ mod string_literal {
4049
4049
}
4050
4050
}
4051
4051
4052
- fn handle_prefer_double ( string_value : & str ) -> String {
4052
+ fn handle_prefer_double ( string_value : & str ) -> PrintItems {
4053
4053
if double_to_single ( string_value) <= 0 {
4054
4054
format_with_double ( string_value)
4055
4055
} else {
4056
4056
format_with_single ( string_value)
4057
4057
}
4058
4058
}
4059
4059
4060
- fn handle_prefer_single ( string_value : & str ) -> String {
4060
+ fn handle_prefer_single ( string_value : & str ) -> PrintItems {
4061
4061
if double_to_single ( string_value) >= 0 {
4062
4062
format_with_single ( string_value)
4063
4063
} else {
4064
4064
format_with_double ( string_value)
4065
4065
}
4066
4066
}
4067
4067
4068
- fn format_with_double ( string_value : & str ) -> String {
4069
- format ! ( "\" {}\" " , string_value. replace( '"' , "\\ \" " ) )
4068
+ fn format_with_double ( string_value : & str ) -> PrintItems {
4069
+ let mut items = PrintItems :: new ( ) ;
4070
+ items. push_str ( "\" " ) ;
4071
+ items. extend ( gen_from_raw_string ( & string_value. replace ( '"' , "\\ \" " ) ) ) ;
4072
+ items. push_str ( "\" " ) ;
4073
+ items
4070
4074
}
4071
4075
4072
- fn format_with_single ( string_value : & str ) -> String {
4073
- format ! ( "'{}'" , string_value. replace( '\'' , "\\ '" ) )
4076
+ fn format_with_single ( string_value : & str ) -> PrintItems {
4077
+ let mut items = PrintItems :: new ( ) ;
4078
+ items. push_str ( "'" ) ;
4079
+ items. extend ( gen_from_raw_string ( & string_value. replace ( '\'' , "\\ '" ) ) ) ;
4080
+ items. push_str ( "'" ) ;
4081
+ items
4074
4082
}
4075
4083
4076
4084
fn double_to_single ( string_value : & str ) -> i32 {
0 commit comments