1- use std:: collections:: HashMap ;
1+ use std:: { borrow :: Cow , collections:: HashMap } ;
22
33use lazy_static:: lazy_static;
44use regex:: { Captures , Regex } ;
@@ -19,15 +19,13 @@ use self::mappings::*;
1919use self :: string_to_object_style:: * ;
2020use self :: util:: * ;
2121
22- fn kebab_case ( str : & str ) -> String {
22+ fn kebab_case ( str : & str ) -> Cow < str > {
2323 lazy_static ! {
2424 static ref KEBAB_REGEX : Regex = Regex :: new( r"[A-Z\u00C0-\u00D6\u00D8-\u00DE]" ) . unwrap( ) ;
2525 }
26- KEBAB_REGEX
27- . replace_all ( str, |caps : & Captures | {
28- format ! ( "-{}" , & caps[ 0 ] . to_lowercase( ) )
29- } )
30- . to_string ( )
26+ KEBAB_REGEX . replace_all ( str, |caps : & Captures | {
27+ format ! ( "-{}" , & caps[ 0 ] . to_lowercase( ) )
28+ } )
3129}
3230
3331fn convert_aria_attribute ( kebab_key : & str ) -> String {
@@ -37,11 +35,11 @@ fn convert_aria_attribute(kebab_key: &str) -> String {
3735 format ! ( "{}-{}" , aria, lowercase_parts)
3836}
3937
40- fn replace_spaces ( s : & str ) -> String {
38+ fn replace_spaces ( s : & str ) -> Cow < str > {
4139 lazy_static ! {
4240 static ref SPACES_REGEX : Regex = Regex :: new( r"[\t\r\n\u0085\u2028\u2029]+" ) . unwrap( ) ;
4341 }
44- SPACES_REGEX . replace_all ( s, |_: & Captures | " " ) . to_string ( )
42+ SPACES_REGEX . replace_all ( s, |_: & Captures | " " )
4543}
4644
4745fn get_value ( attr_name : & str , value : & JsWord ) -> JSXAttrValue {
@@ -105,8 +103,8 @@ impl HastVisitor {
105103 }
106104 }
107105
108- pub fn get_jsx ( & self ) -> Option < JSXElement > {
109- self . jsx . clone ( )
106+ pub fn take_jsx ( & mut self ) -> Option < JSXElement > {
107+ self . jsx . take ( )
110108 }
111109
112110 fn element ( & self , n : & swc_xml:: ast:: Element ) -> JSXElement {
@@ -243,7 +241,7 @@ impl Visit for HastVisitor {
243241pub fn to_swc_ast ( hast : swc_xml:: ast:: Document ) -> Option < JSXElement > {
244242 let mut v = HastVisitor :: new ( ) ;
245243 hast. visit_with ( & mut v) ;
246- v. get_jsx ( )
244+ v. take_jsx ( )
247245}
248246
249247#[ cfg( test) ]
0 commit comments