@@ -21,7 +21,7 @@ use swc_core::{
2121use swc_core:: ecma:: ast:: * ;
2222
2323use crate :: {
24- constants:: { CALC_STATIC_STYLE , COMBINE_NESTING_STYLE , CONVERT_STYLE_PX_FN , CSS_VAR_FN , HM_STYLE , INNER_STYLE , INNER_STYLE_DATA , NESTING_STYLE , NESTINT_STYLE_DATA , RN_CONVERT_STYLE_PX_FN , RN_CONVERT_STYLE_VU_FN } , parse_style_properties:: parse_style_properties, scraper:: Element , style_parser:: StyleValue , style_propetries:: { style_value_type:: StyleValueType , traits:: ToStyleValue , unit:: { Platform , PropertyTuple } } , utils:: {
24+ constants:: { CALC_STATIC_STYLE , COMBINE_NESTING_STYLE , CONVERT_STYLE_PX_FN , CSS_VAR_FN , HM_STYLE , INNER_STYLE , INNER_STYLE_DATA , NESTING_STYLE , NESTINT_STYLE_DATA , RN_CONVERT_STYLE_PX_FN , RN_CONVERT_STYLE_VU_FN , SUPPORT_PSEUDO_KEYS } , parse_style_properties:: parse_style_properties, scraper:: Element , style_parser:: StyleValue , style_propetries:: { style_value_type:: StyleValueType , traits:: ToStyleValue , unit:: { Platform , PropertyTuple } } , utils:: {
2525 create_qualname, get_callee_attributes, is_starts_with_uppercase, prefix_style_key, recursion_jsx_member, split_selector, to_camel_case, to_kebab_case, TSelector
2626 }
2727} ;
@@ -576,7 +576,7 @@ impl VisitMut for ModuleMutVisitor {
576576 let mut insert_key = key. to_string ( ) ;
577577 let mut insert_value = vec ! [ ] ;
578578
579- if ( key . contains ( ":after" ) | | key. contains ( ":before" ) ) && self . platform == Platform :: Harmony {
579+ if ( SUPPORT_PSEUDO_KEYS . into_iter ( ) . any ( |s | key. contains ( s ) ) ) && self . platform == Platform :: Harmony {
580580 let mut pesudo_key = String :: new ( ) ;
581581 let key_arr = key. split ( ":" ) . collect :: < Vec < & str > > ( ) ;
582582 if key_arr. len ( ) == 2 {
@@ -1298,6 +1298,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
12981298
12991299 fn visit_mut_call_expr ( & mut self , n : & mut CallExpr ) {
13001300 let mut has_style = false ;
1301+ let mut should_remove_style = false ;
13011302
13021303 if self . check_is_jsx_callee ( n) {
13031304
@@ -1326,6 +1327,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
13261327 let value = self . process_attribute_lit_value ( lit, has_dynamic_class) ;
13271328 if let Some ( value) = value {
13281329 static_styles = parse_style_values ( value, self . platform . clone ( ) ) ;
1330+ if static_styles. len ( ) > 0 {
1331+ should_remove_style = true ;
1332+ }
13291333 }
13301334 }
13311335 _ => {
@@ -1334,6 +1338,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
13341338 let ( static_props, dynamic_props) = self . process_attribute_expr_value ( expr, has_dynamic_class) ;
13351339 static_styles = static_props;
13361340 dynamic_styles = dynamic_props;
1341+ if static_styles. len ( ) > 0 || dynamic_styles. len ( ) > 0 {
1342+ should_remove_style = true ;
1343+ }
13371344 }
13381345 } ;
13391346 }
@@ -1499,7 +1506,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
14991506 }
15001507 } else {
15011508 // 移除原本的style
1502- if has_style {
1509+ if has_style && should_remove_style {
15031510 if let Some ( attr) = n. args . get_mut ( 1 ) {
15041511 if let Expr :: Object ( object) = & mut * attr. expr {
15051512 let mut index = 0 ;
@@ -1529,6 +1536,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
15291536
15301537 fn visit_mut_jsx_element ( & mut self , n : & mut JSXElement ) {
15311538 let mut has_style = false ;
1539+ let mut should_remove_style = false ;
15321540 let span_key = SpanKey ( n. span ) ;
15331541
15341542 if let Some ( _) = self . jsx_record . borrow_mut ( ) . get ( & span_key) {
@@ -1558,6 +1566,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
15581566 let value = self . process_attribute_lit_value ( lit, has_dynamic_class) ;
15591567 if let Some ( value) = value {
15601568 static_styles = parse_style_values ( value, self . platform . clone ( ) ) ;
1569+ if static_styles. len ( ) > 0 {
1570+ should_remove_style = true ;
1571+ }
15611572 }
15621573 }
15631574 JSXAttrValue :: JSXExprContainer ( expr_container) => {
@@ -1567,6 +1578,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
15671578 let ( static_props, dynamic_props) = self . process_attribute_expr_value ( expr, has_dynamic_class) ;
15681579 static_styles = static_props;
15691580 dynamic_styles = dynamic_props;
1581+ if static_styles. len ( ) > 0 || dynamic_styles. len ( ) > 0 {
1582+ should_remove_style = true ;
1583+ }
15701584 }
15711585 _ => {
15721586 has_style = false ;
@@ -1714,7 +1728,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
17141728 }
17151729 } else {
17161730 // 移除原本的style,从属性上去掉
1717- if has_style {
1731+ if has_style && should_remove_style {
17181732 let attrs = n. opening . attrs . iter ( ) . filter ( |attr| {
17191733 if let JSXAttrOrSpread :: JSXAttr ( attr) = attr {
17201734 if let JSXAttrName :: Ident ( ident) = & attr. name {
0 commit comments