@@ -21,7 +21,7 @@ use swc_core::{
21
21
use swc_core:: ecma:: ast:: * ;
22
22
23
23
use 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:: {
25
25
create_qualname, get_callee_attributes, is_starts_with_uppercase, prefix_style_key, recursion_jsx_member, split_selector, to_camel_case, to_kebab_case, TSelector
26
26
}
27
27
} ;
@@ -576,7 +576,7 @@ impl VisitMut for ModuleMutVisitor {
576
576
let mut insert_key = key. to_string ( ) ;
577
577
let mut insert_value = vec ! [ ] ;
578
578
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 {
580
580
let mut pesudo_key = String :: new ( ) ;
581
581
let key_arr = key. split ( ":" ) . collect :: < Vec < & str > > ( ) ;
582
582
if key_arr. len ( ) == 2 {
@@ -1298,6 +1298,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1298
1298
1299
1299
fn visit_mut_call_expr ( & mut self , n : & mut CallExpr ) {
1300
1300
let mut has_style = false ;
1301
+ let mut should_remove_style = false ;
1301
1302
1302
1303
if self . check_is_jsx_callee ( n) {
1303
1304
@@ -1326,6 +1327,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1326
1327
let value = self . process_attribute_lit_value ( lit, has_dynamic_class) ;
1327
1328
if let Some ( value) = value {
1328
1329
static_styles = parse_style_values ( value, self . platform . clone ( ) ) ;
1330
+ if static_styles. len ( ) > 0 {
1331
+ should_remove_style = true ;
1332
+ }
1329
1333
}
1330
1334
}
1331
1335
_ => {
@@ -1334,6 +1338,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1334
1338
let ( static_props, dynamic_props) = self . process_attribute_expr_value ( expr, has_dynamic_class) ;
1335
1339
static_styles = static_props;
1336
1340
dynamic_styles = dynamic_props;
1341
+ if static_styles. len ( ) > 0 || dynamic_styles. len ( ) > 0 {
1342
+ should_remove_style = true ;
1343
+ }
1337
1344
}
1338
1345
} ;
1339
1346
}
@@ -1499,7 +1506,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1499
1506
}
1500
1507
} else {
1501
1508
// 移除原本的style
1502
- if has_style {
1509
+ if has_style && should_remove_style {
1503
1510
if let Some ( attr) = n. args . get_mut ( 1 ) {
1504
1511
if let Expr :: Object ( object) = & mut * attr. expr {
1505
1512
let mut index = 0 ;
@@ -1529,6 +1536,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1529
1536
1530
1537
fn visit_mut_jsx_element ( & mut self , n : & mut JSXElement ) {
1531
1538
let mut has_style = false ;
1539
+ let mut should_remove_style = false ;
1532
1540
let span_key = SpanKey ( n. span ) ;
1533
1541
1534
1542
if let Some ( _) = self . jsx_record . borrow_mut ( ) . get ( & span_key) {
@@ -1558,6 +1566,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1558
1566
let value = self . process_attribute_lit_value ( lit, has_dynamic_class) ;
1559
1567
if let Some ( value) = value {
1560
1568
static_styles = parse_style_values ( value, self . platform . clone ( ) ) ;
1569
+ if static_styles. len ( ) > 0 {
1570
+ should_remove_style = true ;
1571
+ }
1561
1572
}
1562
1573
}
1563
1574
JSXAttrValue :: JSXExprContainer ( expr_container) => {
@@ -1567,6 +1578,9 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1567
1578
let ( static_props, dynamic_props) = self . process_attribute_expr_value ( expr, has_dynamic_class) ;
1568
1579
static_styles = static_props;
1569
1580
dynamic_styles = dynamic_props;
1581
+ if static_styles. len ( ) > 0 || dynamic_styles. len ( ) > 0 {
1582
+ should_remove_style = true ;
1583
+ }
1570
1584
}
1571
1585
_ => {
1572
1586
has_style = false ;
@@ -1714,7 +1728,7 @@ impl<'i> VisitMut for JSXMutVisitor<'i> {
1714
1728
}
1715
1729
} else {
1716
1730
// 移除原本的style,从属性上去掉
1717
- if has_style {
1731
+ if has_style && should_remove_style {
1718
1732
let attrs = n. opening . attrs . iter ( ) . filter ( |attr| {
1719
1733
if let JSXAttrOrSpread :: JSXAttr ( attr) = attr {
1720
1734
if let JSXAttrName :: Ident ( ident) = & attr. name {
0 commit comments