5656//! - Documentation: <https://styled-components.com/docs/tooling#babel-plugin>
5757
5858use std:: {
59+ borrow:: Cow ,
5960 hash:: { Hash , Hasher } ,
6061 iter:: once,
6162} ;
6263
6364use rustc_hash:: { FxHashSet , FxHasher } ;
6465use serde:: Deserialize ;
6566
66- use oxc_allocator:: { StringBuilder , TakeIn , Vec as ArenaVec } ;
67+ use oxc_allocator:: { TakeIn , Vec as ArenaVec } ;
6768use oxc_ast:: { AstBuilder , NONE , ast:: * } ;
6869use oxc_data_structures:: inline_string:: InlineString ;
6970use oxc_semantic:: SymbolId ;
@@ -894,12 +895,12 @@ impl<'a> CssMinifier<'a> {
894895 let minifier = Self :: new ( ast) ;
895896
896897 let css = if quasis. len ( ) == 1 {
897- & quasis[ 0 ] . value . raw
898+ Cow :: Borrowed ( quasis[ 0 ] . value . raw . as_str ( ) )
898899 } else {
899- minifier . inject_unique_placeholders ( quasis)
900+ Cow :: Owned ( Self :: inject_unique_placeholders ( quasis) )
900901 } ;
901902
902- minifier. minify_css ( css)
903+ minifier. minify_css ( & css)
903904 }
904905
905906 /// Injects unique placeholders into a series of `quasis` to represent expressions.
@@ -915,23 +916,25 @@ impl<'a> CssMinifier<'a> {
915916 /// `["width: ", "px; color: ", ";"]`, and expressions `[width, color]`,
916917 /// this function will produce the string:
917918 /// `"width: __PLACEHOLDER_0__px; color: __PLACEHOLDER_1__;"`
918- fn inject_unique_placeholders ( & self , quasis : & [ TemplateElement ] ) -> & str {
919+ fn inject_unique_placeholders ( quasis : & [ TemplateElement ] ) -> String {
919920 let estimated_capacity: usize = quasis. iter ( ) . map ( |s| s. value . raw . len ( ) ) . sum :: < usize > ( )
920921 + ( quasis. len ( ) - 1 )
921922 * ( Self :: PLACEHOLDER_PREFIX . len ( ) + Self :: PLACEHOLDER_SUFFIX . len ( ) + 2 ) ; // 2 for digits
922923
923- let mut result = StringBuilder :: with_capacity_in ( estimated_capacity, self . ast . allocator ) ;
924+ let mut result = String :: with_capacity ( estimated_capacity) ;
924925
925926 for ( index, val) in quasis. iter ( ) . enumerate ( ) {
926927 result. push_str ( & val. value . raw ) ;
927928 if index < quasis. len ( ) - 1 {
928- result. push_str ( Self :: PLACEHOLDER_PREFIX ) ;
929- result. push_str ( itoa:: Buffer :: new ( ) . format ( index) ) ;
930- result. push_str ( Self :: PLACEHOLDER_SUFFIX ) ;
929+ result. extend ( [
930+ Self :: PLACEHOLDER_PREFIX ,
931+ itoa:: Buffer :: new ( ) . format ( index) ,
932+ Self :: PLACEHOLDER_SUFFIX ,
933+ ] ) ;
931934 }
932935 }
933936
934- result. into_str ( )
937+ result
935938 }
936939
937940 /// Tries to parse a placeholder like `__PLACEHOLDER_0__` from a byte slice.
0 commit comments