1
+ use std:: collections:: HashMap ;
2
+
1
3
use html5ever:: { namespace_url, ns, LocalName , QualName } ;
2
4
use regex:: Regex ;
3
5
use swc_common:: DUMMY_SP ;
4
6
// 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 } ;
6
8
7
9
use crate :: constants:: { CONVERT_STYLE_PREFIX , CONVERT_STYLE_PX_FN } ;
8
10
@@ -91,4 +93,28 @@ pub fn convert_px_to_units(input: String) -> Expr {
91
93
}
92
94
// 如果没有匹配到,则返回原始字符串
93
95
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