11use crate :: utils:: { expression_to_code, is_special_property} ;
22use crate :: ExtractStyleProp ;
33use oxc_allocator:: CloneIn ;
4- use oxc_ast:: ast:: { Expression , JSXAttributeValue , ObjectPropertyKind , PropertyKey } ;
4+ use oxc_ast:: ast:: {
5+ Expression , JSXAttributeValue , ObjectPropertyKind , PropertyKey , TemplateElementValue ,
6+ } ;
57
68use crate :: extract_style:: ExtractStyleValue :: { Dynamic , Static , Typography } ;
79use crate :: extract_style:: { ExtractDynamicStyle , ExtractStaticStyle } ;
@@ -422,14 +424,43 @@ pub fn extract_style_from_expression<'a>(
422424 ) )
423425 } ) ] )
424426 } else {
425- ExtractResult :: ExtractStyle ( vec ! [ ExtractStyleProp :: Static ( Dynamic (
426- ExtractDynamicStyle :: new(
427- name,
428- level,
429- expression_to_code( expression) . as_str( ) ,
430- selector. map( |s| s. into( ) ) ,
431- ) ,
432- ) ) ] )
427+ if typo {
428+ ExtractResult :: ExtractStyle ( vec ! [ ExtractStyleProp :: Expression {
429+ expression: ast_builder. expression_template_literal(
430+ SPAN ,
431+ ast_builder. vec_from_array( [
432+ ast_builder. template_element(
433+ SPAN ,
434+ false ,
435+ TemplateElementValue {
436+ raw: ast_builder. atom( "typo-" ) ,
437+ cooked: None ,
438+ } ,
439+ ) ,
440+ ast_builder. template_element(
441+ SPAN ,
442+ true ,
443+ TemplateElementValue {
444+ raw: ast_builder. atom( "" ) ,
445+ cooked: None ,
446+ } ,
447+ ) ,
448+ ] ) ,
449+ ast_builder
450+ . vec_from_array( [ expression. clone_in( ast_builder. allocator) ] ) ,
451+ ) ,
452+ styles: vec![ ] ,
453+ } ] )
454+ } else {
455+ ExtractResult :: ExtractStyle ( vec ! [ ExtractStyleProp :: Static ( Dynamic (
456+ ExtractDynamicStyle :: new(
457+ name,
458+ level,
459+ expression_to_code( expression) . as_str( ) ,
460+ selector. map( |s| s. into( ) ) ,
461+ ) ,
462+ ) ) ] )
463+ }
433464 }
434465 } else {
435466 ExtractResult :: Maintain
@@ -453,14 +484,43 @@ pub fn extract_style_from_expression<'a>(
453484 if IGNORED_IDENTIFIERS . contains ( & identifier. name . as_str ( ) ) {
454485 ExtractResult :: Maintain
455486 } else if let Some ( name) = name {
456- ExtractResult :: ExtractStyle ( vec ! [ ExtractStyleProp :: Static ( Dynamic (
457- ExtractDynamicStyle :: new(
458- name,
459- level,
460- identifier. name. as_str( ) ,
461- selector. map( |s| s. into( ) ) ,
462- ) ,
463- ) ) ] )
487+ if typo {
488+ ExtractResult :: ExtractStyle ( vec ! [ ExtractStyleProp :: Expression {
489+ expression: ast_builder. expression_template_literal(
490+ SPAN ,
491+ ast_builder. vec_from_array( [
492+ ast_builder. template_element(
493+ SPAN ,
494+ false ,
495+ TemplateElementValue {
496+ raw: ast_builder. atom( "typo-" ) ,
497+ cooked: None ,
498+ } ,
499+ ) ,
500+ ast_builder. template_element(
501+ SPAN ,
502+ true ,
503+ TemplateElementValue {
504+ raw: ast_builder. atom( "" ) ,
505+ cooked: None ,
506+ } ,
507+ ) ,
508+ ] ) ,
509+ ast_builder
510+ . vec_from_array( [ expression. clone_in( ast_builder. allocator) ] ) ,
511+ ) ,
512+ styles: vec![ ] ,
513+ } ] )
514+ } else {
515+ ExtractResult :: ExtractStyle ( vec ! [ ExtractStyleProp :: Static ( Dynamic (
516+ ExtractDynamicStyle :: new(
517+ name,
518+ level,
519+ identifier. name. as_str( ) ,
520+ selector. map( |s| s. into( ) ) ,
521+ ) ,
522+ ) ) ] )
523+ }
464524 } else {
465525 ExtractResult :: Maintain
466526 }
0 commit comments