Skip to content

Commit b698459

Browse files
committed
fix: 遗漏样式属性添加情况
1 parent d8954ae commit b698459

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/visitor.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,28 @@ impl VisitMut for JSXMutVisitor {
532532
],
533533
type_args: None,
534534
});
535-
for attr in &mut n.opening.attrs {
536-
if let JSXAttrOrSpread::JSXAttr(attr) = attr {
537-
if let JSXAttrName::Ident(ident) = &attr.name {
538-
if ident.sym.to_string() == "style" {
539-
attr.value = Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
540-
span: DUMMY_SP,
541-
expr: JSXExpr::Expr(Box::new(fun_call_expr.clone())),
542-
}));
535+
if has_style {
536+
for attr in &mut n.opening.attrs {
537+
if let JSXAttrOrSpread::JSXAttr(attr) = attr {
538+
if let JSXAttrName::Ident(ident) = &attr.name {
539+
if ident.sym.to_string() == "style" {
540+
attr.value = Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
541+
span: DUMMY_SP,
542+
expr: JSXExpr::Expr(Box::new(fun_call_expr.clone())),
543+
}));
544+
}
543545
}
544546
}
545547
}
548+
} else {
549+
n.opening.attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr {
550+
span: DUMMY_SP,
551+
name: JSXAttrName::Ident(Ident::new("style".into(), DUMMY_SP)),
552+
value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
553+
span: DUMMY_SP,
554+
expr: JSXExpr::Expr(Box::new(fun_call_expr)),
555+
})),
556+
}));
546557
}
547558
}
548559
}

0 commit comments

Comments
 (0)