@@ -30,166 +30,161 @@ pub(super) fn extract_style_from_member_expression<'a>(
3030 let mem_expression = & mem. expression . clone_in ( ast_builder. allocator ) ;
3131 let mut ret: Vec < ExtractStyleProp > = vec ! [ ] ;
3232
33- match & mut mem. object {
34- Expression :: ArrayExpression ( array) if !array. elements . is_empty ( ) => {
35- if let Some ( num) = get_number_by_literal_expression ( mem_expression) {
36- if num < 0f64 {
37- return ExtractResult :: default ( ) ;
38- }
39- let mut etc = None ;
40- for ( idx, p) in array. elements . iter_mut ( ) . enumerate ( ) {
41- if let ArrayExpressionElement :: SpreadElement ( sp) = p {
42- etc = Some ( sp. argument . clone_in ( ast_builder. allocator ) ) ;
43- } else if idx as f64 == num
44- && let Some ( p) = p. as_expression_mut ( )
45- {
46- return extract_style_from_expression (
47- ast_builder,
48- name,
49- p,
50- level,
51- selector,
52- ) ;
53- }
54- }
55- return ExtractResult {
56- props : None ,
57- styles : etc
58- . map ( |etc| {
59- vec ! [ ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
60- ExtractDynamicStyle :: new(
61- name. unwrap( ) ,
62- level,
63- & expression_to_code( & Expression :: ComputedMemberExpression (
64- ast_builder. alloc_computed_member_expression(
65- SPAN ,
66- etc,
67- mem_expression. clone_in( ast_builder. allocator) ,
68- false ,
69- ) ,
70- ) ) ,
71- selector. clone( ) ,
72- ) ,
73- ) ) ]
74- } )
75- . unwrap_or_default ( ) ,
76- tag : None ,
77- style_order : None ,
78- style_vars : None ,
79- } ;
33+ if let Expression :: ArrayExpression ( array) = & mut mem. object
34+ && !array. elements . is_empty ( )
35+ {
36+ if let Some ( num) = get_number_by_literal_expression ( mem_expression) {
37+ if num < 0f64 {
38+ return ExtractResult :: default ( ) ;
8039 }
81-
82- let mut map = BTreeMap :: new ( ) ;
40+ let mut etc = None ;
8341 for ( idx, p) in array. elements . iter_mut ( ) . enumerate ( ) {
8442 if let ArrayExpressionElement :: SpreadElement ( sp) = p {
85- map. insert (
86- idx. to_string ( ) ,
87- Box :: new ( ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
43+ etc = Some ( sp. argument . clone_in ( ast_builder. allocator ) ) ;
44+ } else if idx as f64 == num
45+ && let Some ( p) = p. as_expression_mut ( )
46+ {
47+ return extract_style_from_expression ( ast_builder, name, p, level, selector) ;
48+ }
49+ }
50+ return ExtractResult {
51+ props : None ,
52+ styles : etc
53+ . map ( |etc| {
54+ vec ! [ ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
8855 ExtractDynamicStyle :: new(
8956 name. unwrap( ) ,
9057 level,
9158 & expression_to_code( & Expression :: ComputedMemberExpression (
9259 ast_builder. alloc_computed_member_expression(
9360 SPAN ,
94- sp . argument . clone_in ( ast_builder . allocator ) ,
61+ etc ,
9562 mem_expression. clone_in( ast_builder. allocator) ,
9663 false ,
9764 ) ,
9865 ) ) ,
9966 selector. clone( ) ,
10067 ) ,
101- ) ) ) ,
102- ) ;
103- } else if let Some ( p) = p. as_expression_mut ( ) {
104- map. insert (
105- idx. to_string ( ) ,
106- Box :: new ( ExtractStyleProp :: StaticArray (
107- extract_style_from_expression ( ast_builder, name, p, level, selector)
108- . styles ,
109- ) ) ,
110- ) ;
111- }
112- }
113-
114- ret. push ( ExtractStyleProp :: MemberExpression {
115- expression : mem_expression. clone_in ( ast_builder. allocator ) ,
116- map,
117- } ) ;
68+ ) ) ]
69+ } )
70+ . unwrap_or_default ( ) ,
71+ tag : None ,
72+ style_order : None ,
73+ style_vars : None ,
74+ } ;
11875 }
119- Expression :: ObjectExpression ( obj) if !obj. properties . is_empty ( ) => {
120- let mut map = BTreeMap :: new ( ) ;
121- if let Some ( k) = get_string_by_literal_expression ( mem_expression) {
122- let mut etc = None ;
123- for p in obj. properties . iter_mut ( ) {
124- if let ObjectPropertyKind :: ObjectProperty ( o) = p {
125- if let PropertyKey :: StaticIdentifier ( ref pk) = o. key
126- && pk. name == k
127- {
128- return ExtractResult {
129- styles : extract_style_from_expression (
130- ast_builder,
131- name,
132- & mut o. value ,
133- level,
134- selector,
135- )
136- . styles ,
137- ..ExtractResult :: default ( )
138- } ;
139- }
140- } else if let ObjectPropertyKind :: SpreadProperty ( sp) = p {
141- etc = Some ( sp. argument . clone_in ( ast_builder. allocator ) ) ;
142- }
143- }
14476
145- match etc {
146- None => return ExtractResult :: default ( ) ,
147- Some ( etc) => ret. push ( ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
77+ let mut map = BTreeMap :: new ( ) ;
78+ for ( idx, p) in array. elements . iter_mut ( ) . enumerate ( ) {
79+ if let ArrayExpressionElement :: SpreadElement ( sp) = p {
80+ map. insert (
81+ idx. to_string ( ) ,
82+ Box :: new ( ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
14883 ExtractDynamicStyle :: new (
14984 name. unwrap ( ) ,
15085 level,
15186 & expression_to_code ( & Expression :: ComputedMemberExpression (
15287 ast_builder. alloc_computed_member_expression (
15388 SPAN ,
154- etc ,
89+ sp . argument . clone_in ( ast_builder . allocator ) ,
15590 mem_expression. clone_in ( ast_builder. allocator ) ,
15691 false ,
15792 ) ,
15893 ) ) ,
15994 selector. clone ( ) ,
16095 ) ,
16196 ) ) ) ,
162- }
97+ ) ;
98+ } else if let Some ( p) = p. as_expression_mut ( ) {
99+ map. insert (
100+ idx. to_string ( ) ,
101+ Box :: new ( ExtractStyleProp :: StaticArray (
102+ extract_style_from_expression ( ast_builder, name, p, level, selector) . styles ,
103+ ) ) ,
104+ ) ;
163105 }
106+ }
164107
108+ ret. push ( ExtractStyleProp :: MemberExpression {
109+ expression : mem_expression. clone_in ( ast_builder. allocator ) ,
110+ map,
111+ } ) ;
112+ } else if let Expression :: ObjectExpression ( obj) = & mut mem. object
113+ && !obj. properties . is_empty ( )
114+ {
115+ let mut map = BTreeMap :: new ( ) ;
116+ if let Some ( k) = get_string_by_literal_expression ( mem_expression) {
117+ let mut etc = None ;
165118 for p in obj. properties . iter_mut ( ) {
166- if let ObjectPropertyKind :: ObjectProperty ( o) = p
167- && let PropertyKey :: StaticIdentifier ( _)
168- | PropertyKey :: NumericLiteral ( _)
169- | PropertyKey :: StringLiteral ( _) = o. key
170- {
171- map. insert (
172- o. key . name ( ) . unwrap ( ) . to_string ( ) ,
173- Box :: new ( ExtractStyleProp :: StaticArray (
174- extract_style_from_expression (
119+ if let ObjectPropertyKind :: ObjectProperty ( o) = p {
120+ if let PropertyKey :: StaticIdentifier ( ref pk) = o. key
121+ && pk. name == k
122+ {
123+ return ExtractResult {
124+ styles : extract_style_from_expression (
175125 ast_builder,
176126 name,
177127 & mut o. value ,
178128 level,
179129 selector,
180130 )
181131 . styles ,
182- ) ) ,
183- ) ;
132+ ..ExtractResult :: default ( )
133+ } ;
134+ }
135+ } else if let ObjectPropertyKind :: SpreadProperty ( sp) = p {
136+ etc = Some ( sp. argument . clone_in ( ast_builder. allocator ) ) ;
184137 }
185138 }
186- ret. push ( ExtractStyleProp :: MemberExpression {
187- expression : mem_expression. clone_in ( ast_builder. allocator ) ,
188- map,
189- } ) ;
139+
140+ match etc {
141+ None => return ExtractResult :: default ( ) ,
142+ Some ( etc) => ret. push ( ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
143+ ExtractDynamicStyle :: new (
144+ name. unwrap ( ) ,
145+ level,
146+ & expression_to_code ( & Expression :: ComputedMemberExpression (
147+ ast_builder. alloc_computed_member_expression (
148+ SPAN ,
149+ etc,
150+ mem_expression. clone_in ( ast_builder. allocator ) ,
151+ false ,
152+ ) ,
153+ ) ) ,
154+ selector. clone ( ) ,
155+ ) ,
156+ ) ) ) ,
157+ }
190158 }
191- Expression :: Identifier ( _) => ret. push ( ExtractStyleProp :: Static (
192- ExtractStyleValue :: Dynamic ( ExtractDynamicStyle :: new (
159+
160+ for p in obj. properties . iter_mut ( ) {
161+ if let ObjectPropertyKind :: ObjectProperty ( o) = p
162+ && let PropertyKey :: StaticIdentifier ( _)
163+ | PropertyKey :: NumericLiteral ( _)
164+ | PropertyKey :: StringLiteral ( _) = o. key
165+ {
166+ map. insert (
167+ o. key . name ( ) . unwrap ( ) . to_string ( ) ,
168+ Box :: new ( ExtractStyleProp :: StaticArray (
169+ extract_style_from_expression (
170+ ast_builder,
171+ name,
172+ & mut o. value ,
173+ level,
174+ selector,
175+ )
176+ . styles ,
177+ ) ) ,
178+ ) ;
179+ }
180+ }
181+ ret. push ( ExtractStyleProp :: MemberExpression {
182+ expression : mem_expression. clone_in ( ast_builder. allocator ) ,
183+ map,
184+ } ) ;
185+ } else if let Expression :: Identifier ( _) = & mut mem. object {
186+ ret. push ( ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
187+ ExtractDynamicStyle :: new (
193188 name. unwrap ( ) ,
194189 level,
195190 & expression_to_code ( & Expression :: ComputedMemberExpression (
@@ -201,10 +196,9 @@ pub(super) fn extract_style_from_member_expression<'a>(
201196 ) ,
202197 ) ) ,
203198 selector. clone ( ) ,
204- ) ) ,
205- ) ) ,
206- _ => { }
207- } ;
199+ ) ,
200+ ) ) )
201+ }
208202
209203 ExtractResult {
210204 styles : ret,
0 commit comments