@@ -156,91 +156,84 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> {
156156 } ;
157157 } else {
158158 let r = util_type. as_ref ( ) ;
159- * it = match r {
160- UtilType :: Css => {
161- let ExtractResult {
162- mut styles,
163- style_order,
164- ..
165- } = extract_style_from_expression (
159+ * it = if let UtilType :: Css = r {
160+ let ExtractResult {
161+ mut styles,
162+ style_order,
163+ ..
164+ } = extract_style_from_expression (
165+ & self . ast ,
166+ None ,
167+ if let Argument :: SpreadElement ( spread) = & mut call. arguments [ 0 ] {
168+ & mut spread. argument
169+ } else {
170+ call. arguments [ 0 ] . to_expression_mut ( )
171+ } ,
172+ 0 ,
173+ & None ,
174+ ) ;
175+
176+ if styles. is_empty ( ) {
177+ self . ast
178+ . expression_string_literal ( SPAN , self . ast . atom ( "" ) , None )
179+ } else {
180+ // css can not reachable
181+ let class_name = gen_class_names (
166182 & self . ast ,
167- None ,
168- if let Argument :: SpreadElement ( spread) = & mut call. arguments [ 0 ] {
169- & mut spread. argument
170- } else {
171- call. arguments [ 0 ] . to_expression_mut ( )
172- } ,
173- 0 ,
174- & None ,
183+ & mut styles,
184+ style_order,
185+ self . split_filename . as_deref ( ) ,
175186 ) ;
176187
177- if styles. is_empty ( ) {
188+ // already set style order
189+ self . styles
190+ . extend ( styles. into_iter ( ) . flat_map ( |ex| ex. extract ( ) ) ) ;
191+ if let Some ( cls) = class_name {
192+ cls
193+ } else {
178194 self . ast
179195 . expression_string_literal ( SPAN , self . ast . atom ( "" ) , None )
180- } else {
181- // css can not reachable
182- let class_name = gen_class_names (
183- & self . ast ,
184- & mut styles,
185- style_order,
186- self . split_filename . as_deref ( ) ,
187- ) ;
188-
189- // already set style order
190- self . styles
191- . extend ( styles. into_iter ( ) . flat_map ( |ex| ex. extract ( ) ) ) ;
192- if let Some ( cls) = class_name {
193- cls
194- } else {
195- self . ast . expression_string_literal (
196- SPAN ,
197- self . ast . atom ( "" ) ,
198- None ,
199- )
200- }
201196 }
202197 }
203- UtilType :: Keyframes => {
204- let KeyframesExtractResult { keyframes } =
205- extract_keyframes_from_expression (
206- & self . ast ,
207- if let Argument :: SpreadElement ( spread) = & mut call. arguments [ 0 ]
208- {
209- & mut spread. argument
210- } else {
211- call. arguments [ 0 ] . to_expression_mut ( )
212- } ,
213- ) ;
214-
215- let name = keyframes
216- . extract ( self . split_filename . as_deref ( ) )
217- . to_string ( ) ;
218- self . styles . insert ( ExtractStyleValue :: Keyframes ( keyframes) ) ;
219- self . ast
220- . expression_string_literal ( SPAN , self . ast . atom ( & name) , None )
221- }
222- UtilType :: GlobalCss => {
223- let GlobalExtractResult {
224- styles,
225- style_order,
226- } = extract_global_style_from_expression (
198+ } else if let UtilType :: Keyframes = r {
199+ let KeyframesExtractResult { keyframes } =
200+ extract_keyframes_from_expression (
227201 & self . ast ,
228202 if let Argument :: SpreadElement ( spread) = & mut call. arguments [ 0 ] {
229203 & mut spread. argument
230204 } else {
231205 call. arguments [ 0 ] . to_expression_mut ( )
232206 } ,
233- & self . filename ,
234207 ) ;
235- // already set style order
236- self . styles . extend ( styles. into_iter ( ) . flat_map ( |mut ex| {
237- if let ExtractStyleProp :: Static ( css) = & mut ex {
238- css. set_style_order ( style_order. unwrap_or ( 0 ) ) ;
239- }
240- ex. extract ( )
241- } ) ) ;
242- self . ast . expression_identifier ( SPAN , self . ast . atom ( "" ) )
243- }
208+
209+ let name = keyframes
210+ . extract ( self . split_filename . as_deref ( ) )
211+ . to_string ( ) ;
212+ self . styles . insert ( ExtractStyleValue :: Keyframes ( keyframes) ) ;
213+ self . ast
214+ . expression_string_literal ( SPAN , self . ast . atom ( & name) , None )
215+ } else {
216+ // global
217+ let GlobalExtractResult {
218+ styles,
219+ style_order,
220+ } = extract_global_style_from_expression (
221+ & self . ast ,
222+ if let Argument :: SpreadElement ( spread) = & mut call. arguments [ 0 ] {
223+ & mut spread. argument
224+ } else {
225+ call. arguments [ 0 ] . to_expression_mut ( )
226+ } ,
227+ & self . filename ,
228+ ) ;
229+ // already set style order
230+ self . styles . extend ( styles. into_iter ( ) . flat_map ( |mut ex| {
231+ if let ExtractStyleProp :: Static ( css) = & mut ex {
232+ css. set_style_order ( style_order. unwrap_or ( 0 ) ) ;
233+ }
234+ ex. extract ( )
235+ } ) ) ;
236+ self . ast . expression_identifier ( SPAN , self . ast . atom ( "" ) )
244237 }
245238 }
246239 }
@@ -254,56 +247,49 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> {
254247 . iter ( )
255248 . map ( |quasi| quasi. value . raw . to_string ( ) )
256249 . collect :: < String > ( ) ;
257- match css_type. as_ref ( ) {
258- UtilType :: Css => {
259- let styles = css_to_style ( & css_str, 0 , & None ) ;
260- let class_name = gen_class_names (
261- & self . ast ,
262- & mut styles
263- . iter ( )
264- . map ( |ex| {
265- ExtractStyleProp :: Static ( ExtractStyleValue :: Static ( ex. clone ( ) ) )
266- } )
267- . collect :: < Vec < _ > > ( ) ,
268- None ,
269- self . split_filename . as_deref ( ) ,
270- ) ;
250+ let r = css_type. as_ref ( ) ;
251+ * it = if let UtilType :: Css = r {
252+ let styles = css_to_style ( & css_str, 0 , & None ) ;
253+ let class_name = gen_class_names (
254+ & self . ast ,
255+ & mut styles
256+ . iter ( )
257+ . map ( |ex| ExtractStyleProp :: Static ( ExtractStyleValue :: Static ( ex. clone ( ) ) ) )
258+ . collect :: < Vec < _ > > ( ) ,
259+ None ,
260+ self . split_filename . as_deref ( ) ,
261+ ) ;
271262
272- if let Some ( cls) = class_name {
273- * it = cls;
274- } else {
275- * it = self
276- . ast
277- . expression_string_literal ( SPAN , self . ast . atom ( "" ) , None ) ;
278- }
279- // already set style order
280- self . styles
281- . extend ( styles. into_iter ( ) . map ( ExtractStyleValue :: Static ) ) ;
263+ self . styles
264+ . extend ( styles. into_iter ( ) . map ( ExtractStyleValue :: Static ) ) ;
265+ if let Some ( cls) = class_name {
266+ cls
267+ } else {
268+ self . ast
269+ . expression_string_literal ( SPAN , self . ast . atom ( "" ) , None )
282270 }
283- UtilType :: Keyframes => {
284- let keyframes = ExtractKeyframes {
285- keyframes : keyframes_to_keyframes_style ( & css_str) ,
286- } ;
287- let name = keyframes
288- . extract ( self . split_filename . as_deref ( ) )
289- . to_string ( ) ;
271+ // already set style order
272+ } else if let UtilType :: Keyframes = r {
273+ let keyframes = ExtractKeyframes {
274+ keyframes : keyframes_to_keyframes_style ( & css_str) ,
275+ } ;
276+ let name = keyframes
277+ . extract ( self . split_filename . as_deref ( ) )
278+ . to_string ( ) ;
290279
291- self . styles . insert ( ExtractStyleValue :: Keyframes ( keyframes) ) ;
292- * it = self
293- . ast
294- . expression_string_literal ( SPAN , self . ast . atom ( & name) , None ) ;
295- }
296- UtilType :: GlobalCss => {
297- let optimized_css = optimize_css_block ( & css_str) ;
298- if !optimized_css. is_empty ( ) {
299- let css = ExtractStyleValue :: Css ( ExtractCss {
300- css : optimized_css,
301- file : self . filename . clone ( ) ,
302- } ) ;
303- self . styles . insert ( css) ;
304- }
305- * it = self . ast . expression_identifier ( SPAN , self . ast . atom ( "" ) ) ;
280+ self . styles . insert ( ExtractStyleValue :: Keyframes ( keyframes) ) ;
281+ self . ast
282+ . expression_string_literal ( SPAN , self . ast . atom ( & name) , None )
283+ } else {
284+ let optimized_css = optimize_css_block ( & css_str) ;
285+ if !optimized_css. is_empty ( ) {
286+ let css = ExtractStyleValue :: Css ( ExtractCss {
287+ css : optimized_css,
288+ file : self . filename . clone ( ) ,
289+ } ) ;
290+ self . styles . insert ( css) ;
306291 }
292+ self . ast . expression_identifier ( SPAN , self . ast . atom ( "" ) )
307293 }
308294 }
309295 }
0 commit comments