1+ use std:: collections:: HashMap ;
2+
13use html5ever:: { namespace_url, ns, LocalName , QualName } ;
24use regex:: Regex ;
35use swc_common:: DUMMY_SP ;
46// use lightningcss::values::number::CSSNumber;
5- use swc_ecma_ast:: { JSXMemberExpr , JSXObject , Callee , Expr , CallExpr , Ident , Lit , Number } ;
7+ use swc_ecma_ast:: { JSXMemberExpr , JSXObject , Callee , Expr , CallExpr , Ident , Lit , Number , PropOrSpread , Prop , PropName } ;
68
79use crate :: constants:: { CONVERT_STYLE_PREFIX , CONVERT_STYLE_PX_FN } ;
810
@@ -91,4 +93,28 @@ pub fn convert_px_to_units(input: String) -> Expr {
9193 }
9294 // 如果没有匹配到,则返回原始字符串
9395 Expr :: Lit ( Lit :: Str ( input. into ( ) ) )
94- }
96+ }
97+
98+ pub fn get_callee_attributes ( callee : & CallExpr ) -> HashMap < String , Box < Expr > > {
99+ let mut attributes = HashMap :: new ( ) ;
100+
101+ if let Some ( arg) = callee. args . get ( 1 ) {
102+ if let Expr :: Object ( object) = & * arg. expr {
103+ for prop in object. props . iter ( ) {
104+ if let PropOrSpread :: Prop ( prop) = prop {
105+ if let Prop :: KeyValue ( key_value_prop) = & * * prop {
106+ let name = match & key_value_prop. key {
107+ PropName :: Ident ( ident) => ident. sym . to_string ( ) ,
108+ PropName :: Str ( str) => str. value . to_string ( ) ,
109+ _ => "" . to_string ( ) ,
110+ } ;
111+
112+ attributes. insert ( name, key_value_prop. value . clone ( ) ) ;
113+ }
114+ }
115+ }
116+ }
117+ }
118+
119+ attributes
120+ }
0 commit comments