@@ -56,25 +56,22 @@ pub fn extract_style_from_expression<'a>(
5656 if name == "styleOrder" {
5757 style_order = get_number_by_literal_expression ( & prop. value )
5858 . map ( |v| v as u8 ) ;
59- continue ;
60- }
61- if name == "styleVars" {
59+ } else if name == "styleVars" {
6260 style_vars =
6361 Some ( prop. value . clone_in ( ast_builder. allocator ) ) ;
64- continue ;
62+ } else {
63+ let ExtractResult {
64+ styles, tag : _tag, ..
65+ } = extract_style_from_expression (
66+ ast_builder,
67+ Some ( & name) ,
68+ & mut prop. value ,
69+ 0 ,
70+ & None ,
71+ ) ;
72+ props_styles. extend ( styles) ;
73+ tag = _tag. or ( tag) ;
6574 }
66-
67- let ExtractResult {
68- styles, tag : _tag, ..
69- } = extract_style_from_expression (
70- ast_builder,
71- Some ( & name) ,
72- & mut prop. value ,
73- 0 ,
74- & None ,
75- ) ;
76- props_styles. extend ( styles) ;
77- tag = _tag. or ( tag) ;
7875 }
7976 true
8077 } else {
@@ -302,73 +299,70 @@ pub fn extract_style_from_expression<'a>(
302299 extract_style_from_member_expression ( ast_builder, name, mem, level, selector)
303300 }
304301 Expression :: TemplateLiteral ( tmp) => {
305- if let Some ( name) = name {
306- if tmp. quasis . len ( ) == 1 {
307- ExtractResult {
308- styles : vec ! [ ExtractStyleProp :: Static ( if typo {
309- ExtractStyleValue :: Typography ( tmp. quasis[ 0 ] . value. raw. to_string( ) )
310- } else {
311- ExtractStyleValue :: Static ( ExtractStaticStyle :: new(
312- name,
313- & tmp. quasis[ 0 ] . value. raw,
314- level,
315- selector. clone( ) ,
316- ) )
317- } ) ] ,
318- ..ExtractResult :: default ( )
319- }
320- } else if typo {
321- ExtractResult {
322- styles : vec ! [ ExtractStyleProp :: Expression {
323- expression: ast_builder. expression_template_literal(
324- SPAN ,
325- ast_builder. vec_from_array( [
326- ast_builder. template_element(
327- SPAN ,
328- TemplateElementValue {
329- raw: ast_builder. atom( "typo-" ) ,
330- cooked: None ,
331- } ,
332- false ,
333- ) ,
334- ast_builder. template_element(
335- SPAN ,
336- TemplateElementValue {
337- raw: ast_builder. atom( "" ) ,
338- cooked: None ,
339- } ,
340- true ,
341- ) ,
342- ] ) ,
343- ast_builder. vec_from_array( [
344- expression. clone_in( ast_builder. allocator)
345- ] ) ,
346- ) ,
347- styles: vec![ ] ,
348- } ] ,
349- ..ExtractResult :: default ( )
350- }
351- } else {
352- ExtractResult {
353- styles : vec ! [ ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
354- ExtractDynamicStyle :: new(
355- name,
356- level,
357- & expression_to_code( expression) ,
358- selector. clone( ) ,
359- ) ,
360- ) ) ] ,
361- ..ExtractResult :: default ( )
362- }
302+ let name = name. unwrap ( ) ;
303+ if tmp. quasis . len ( ) == 1 {
304+ ExtractResult {
305+ styles : vec ! [ ExtractStyleProp :: Static ( if typo {
306+ ExtractStyleValue :: Typography ( tmp. quasis[ 0 ] . value. raw. to_string( ) )
307+ } else {
308+ ExtractStyleValue :: Static ( ExtractStaticStyle :: new(
309+ name,
310+ & tmp. quasis[ 0 ] . value. raw,
311+ level,
312+ selector. clone( ) ,
313+ ) )
314+ } ) ] ,
315+ ..ExtractResult :: default ( )
316+ }
317+ } else if typo {
318+ ExtractResult {
319+ styles : vec ! [ ExtractStyleProp :: Expression {
320+ expression: ast_builder. expression_template_literal(
321+ SPAN ,
322+ ast_builder. vec_from_array( [
323+ ast_builder. template_element(
324+ SPAN ,
325+ TemplateElementValue {
326+ raw: ast_builder. atom( "typo-" ) ,
327+ cooked: None ,
328+ } ,
329+ false ,
330+ ) ,
331+ ast_builder. template_element(
332+ SPAN ,
333+ TemplateElementValue {
334+ raw: ast_builder. atom( "" ) ,
335+ cooked: None ,
336+ } ,
337+ true ,
338+ ) ,
339+ ] ) ,
340+ ast_builder
341+ . vec_from_array( [ expression. clone_in( ast_builder. allocator) ] ) ,
342+ ) ,
343+ styles: vec![ ] ,
344+ } ] ,
345+ ..ExtractResult :: default ( )
363346 }
364347 } else {
365- ExtractResult :: default ( )
348+ ExtractResult {
349+ styles : vec ! [ ExtractStyleProp :: Static ( ExtractStyleValue :: Dynamic (
350+ ExtractDynamicStyle :: new(
351+ name,
352+ level,
353+ & expression_to_code( expression) ,
354+ selector. clone( ) ,
355+ ) ,
356+ ) ) ] ,
357+ ..ExtractResult :: default ( )
358+ }
366359 }
367360 }
368361 Expression :: Identifier ( identifier) => {
369362 if IGNORED_IDENTIFIERS . contains ( & identifier. name . as_str ( ) ) {
370363 ExtractResult :: default ( )
371- } else if let Some ( name) = name {
364+ } else {
365+ let name = name. unwrap ( ) ;
372366 if typo {
373367 ExtractResult {
374368 styles : vec ! [ ExtractStyleProp :: Expression {
@@ -419,8 +413,6 @@ pub fn extract_style_from_expression<'a>(
419413 ..ExtractResult :: default ( )
420414 }
421415 }
422- } else {
423- ExtractResult :: default ( )
424416 }
425417 }
426418 Expression :: LogicalExpression ( logical) => {
0 commit comments