Skip to content

Commit 94a533e

Browse files
committed
fix: __inner_style__ 要符合 JSON 定义
1 parent 9f58840 commit 94a533e

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

__test__/index.spec.mjs.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Generated by [AVA](https://avajs.dev).
1111
`import React from 'react';␊
1212
import './Mod.scss';␊
1313
var __inner_style__ = {␊
14-
cnt_col: {␊
14+
"cnt_col": {␊
1515
display: "flex",␊
1616
flexDirection: "column",␊
1717
alignItems: "flex-start",␊
@@ -20,7 +20,7 @@ Generated by [AVA](https://avajs.dev).
2020
width: "145px",␊
2121
height: "50px"␊
2222
},␊
23-
cnt_row: {␊
23+
"cnt_row": {␊
2424
width: "176px",␊
2525
height: "24px",␊
2626
borderRadius: "100px",␊
@@ -35,7 +35,7 @@ Generated by [AVA](https://avajs.dev).
3535
paddingTop: "8px",␊
3636
paddingBottom: "8px"␊
3737
},␊
38-
cnt_row1: {␊
38+
"cnt_row1": {␊
3939
display: "flex",␊
4040
alignItems: "center",␊
4141
justifyContent: "flex-start",␊
@@ -44,7 +44,7 @@ Generated by [AVA](https://avajs.dev).
4444
width: "311px",␊
4545
height: "50px"␊
4646
},␊
47-
cnt_row2: {␊
47+
"cnt_row2": {␊
4848
borderWidth: "1px",␊
4949
borderStyle: "solid",␊
5050
borderColor: "#999",␊
@@ -65,59 +65,59 @@ Generated by [AVA](https://avajs.dev).
6565
paddingBottom: "4px",␊
6666
zIndex: "12"␊
6767
},␊
68-
cnt_row3: {␊
68+
"cnt_row3": {␊
6969
display: "flex",␊
7070
alignItems: "center",␊
7171
justifyContent: "space-between",␊
7272
gap: "-311px",␊
7373
width: "311px",␊
7474
height: "44px"␊
7575
},␊
76-
icon: {␊
76+
"icon": {␊
7777
width: "18px",␊
7878
height: "18px"␊
7979
},␊
80-
icon1: {␊
80+
"icon1": {␊
8181
width: "15px",␊
8282
height: "15px"␊
8383
},␊
84-
img: {␊
84+
"img": {␊
8585
width: "50px",␊
8686
height: "50px"␊
8787
},␊
88-
img1: {␊
88+
"img1": {␊
8989
width: "6px",␊
9090
height: "10px"␊
9191
},␊
92-
instruction: {␊
92+
"instruction": {␊
9393
color: "#fff",␊
9494
fontSize: "12px",␊
9595
lineHeight: "1",␊
9696
flexShrink: "0px",␊
9797
display: "inline-flex"␊
9898
},␊
99-
instruction1: {␊
99+
"instruction1": {␊
100100
color: "#000",␊
101101
fontSize: "16px",␊
102102
lineHeight: "1",␊
103103
flexShrink: "0px",␊
104104
width: "116px",␊
105105
display: "inline-flex"␊
106106
},␊
107-
instruction2: {␊
107+
"instruction2": {␊
108108
color: "#999",␊
109109
fontSize: "11px",␊
110110
lineHeight: "1.36",␊
111111
textAlign: "center",␊
112112
flexShrink: "0px",␊
113113
overflow: "hidden"␊
114114
},␊
115-
line1: {␊
115+
"line1": {␊
116116
textOverflow: "ellipsis",␊
117117
whiteSpace: "nowrap",␊
118118
overflow: "hidden"␊
119119
},␊
120-
mod: {␊
120+
"mod": {␊
121121
backgroundColor: "#fff6f0",␊
122122
borderRadius: "8px",␊
123123
width: "343px",␊
@@ -135,21 +135,21 @@ Generated by [AVA](https://avajs.dev).
135135
paddingTop: "29px",␊
136136
paddingBottom: "29px"␊
137137
},␊
138-
txt: {␊
138+
"txt": {␊
139139
color: "#999",␊
140140
fontSize: "12px",␊
141141
lineHeight: "1",␊
142142
flexShrink: "0px",␊
143143
display: "inline-flex"␊
144144
},␊
145-
txt1: {␊
145+
"txt1": {␊
146146
color: "#222",␊
147147
fontSize: "11px",␊
148148
lineHeight: "1.36",␊
149149
textAlign: "center",␊
150150
flexShrink: "0px"␊
151151
},␊
152-
txt2: {␊
152+
"txt2": {␊
153153
color: "#999",␊
154154
fontSize: "12px",␊
155155
lineHeight: "1.83",␊

__test__/index.spec.mjs.snap

7 Bytes
Binary file not shown.

src/visitor.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ use std::{
66
};
77

88
use html5ever::{tendril::StrTendril, Attribute};
9-
use lightningcss::{stylesheet::PrinterOptions, traits::ToCss, targets::{Targets, Features}};
9+
use lightningcss::{
10+
stylesheet::PrinterOptions,
11+
targets::{Features, Targets},
12+
traits::ToCss,
13+
};
1014
use swc_common::{Span, DUMMY_SP};
1115
use swc_ecma_ast::{
1216
BindingIdent, CallExpr, Callee, Decl, Expr, ExprOrSpread, Ident, ImportDecl, ImportSpecifier,
1317
JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXElement, JSXElementName, JSXExpr,
1418
JSXExprContainer, JSXFragment, KeyValueProp, Lit, Module, ModuleDecl, ModuleItem, Null,
15-
ObjectLit, Pat, Prop, PropName, PropOrSpread, Stmt, VarDecl, VarDeclKind, VarDeclarator,
19+
ObjectLit, Pat, Prop, PropName, PropOrSpread, Stmt, Str, VarDecl, VarDeclKind, VarDeclarator,
1620
};
1721
use swc_ecma_visit::{
1822
noop_visit_mut_type, noop_visit_type, Visit, VisitAll, VisitAllWith, VisitMut, VisitMutWith,
@@ -213,7 +217,7 @@ impl<'a> VisitMut for ModuleMutVisitor<'a> {
213217
.iter()
214218
.map(|(key, value)| {
215219
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
216-
key: PropName::Ident(Ident::new(key.to_string().into(), DUMMY_SP)),
220+
key: PropName::Str(Str::from(key.as_str())),
217221
value: Box::new(Expr::Object(ObjectLit {
218222
span: DUMMY_SP,
219223
props: value
@@ -297,7 +301,7 @@ impl<'a> JSXMutVisitor<'a> {
297301

298302
fn properties_to_object_lit_props(
299303
&self,
300-
properties: &Vec<(&String, &String)>
304+
properties: &Vec<(&String, &String)>,
301305
) -> Vec<PropOrSpread> {
302306
properties
303307
.iter()
@@ -399,7 +403,9 @@ impl<'a> VisitMut for JSXMutVisitor<'a> {
399403
span: DUMMY_SP,
400404
expr: JSXExpr::Expr(Box::new(Expr::Object(ObjectLit {
401405
span: DUMMY_SP,
402-
props: self.properties_to_object_lit_props(&properties_entries).into(),
406+
props: self
407+
.properties_to_object_lit_props(&properties_entries)
408+
.into(),
403409
}))),
404410
}));
405411
}
@@ -550,7 +556,9 @@ impl<'a> VisitMut for JSXMutVisitor<'a> {
550556
span: DUMMY_SP,
551557
expr: JSXExpr::Expr(Box::new(Expr::Object(ObjectLit {
552558
span: DUMMY_SP,
553-
props: self.properties_to_object_lit_props(&properties_entries).into(),
559+
props: self
560+
.properties_to_object_lit_props(&properties_entries)
561+
.into(),
554562
}))),
555563
}));
556564
}
@@ -565,7 +573,9 @@ impl<'a> VisitMut for JSXMutVisitor<'a> {
565573
span: DUMMY_SP,
566574
expr: JSXExpr::Expr(Box::new(Expr::Object(ObjectLit {
567575
span: DUMMY_SP,
568-
props: self.properties_to_object_lit_props(&properties_entries).into(),
576+
props: self
577+
.properties_to_object_lit_props(&properties_entries)
578+
.into(),
569579
}))),
570580
})),
571581
}));

0 commit comments

Comments
 (0)