Skip to content

Commit 8ae182e

Browse files
Upgrade swc_core to 46.0.3 (#170)
1 parent 5ad4277 commit 8ae182e

File tree

6 files changed

+69
-90
lines changed

6 files changed

+69
-90
lines changed

Cargo.lock

Lines changed: 34 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ serde = "1.0.207"
2222
serde_json = "1.0.125"
2323
regex = "1.10.6"
2424
once_cell = "1.19.0"
25-
swc_core = { version = "45.0.2", features = [
25+
swc_core = { version = "46.0.3", features = [
2626
"ecma_plugin_transform",
2727
"ecma_utils",
2828
"ecma_visit",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Below is a table referencing the swc_core version used during the plugin build,
111111
| `5.6.0` ~ `5.6.1` | [`27.0.6`](https://plugins.swc.rs/versions/range/364) |
112112
| `5.7.0` | [`39.0.3`](https://plugins.swc.rs/versions/range/426) |
113113
| `5.8.0` | [`45.0.2`](https://plugins.swc.rs/versions/range/497) |
114+
| `5.9.0` | [`46.0.3`](https://plugins.swc.rs/versions/range/713) |
114115

115116
> **Note**
116117
> next `v13.2.4` ~ `v13.3.1` cannot execute SWC Wasm plugins, due to a [bug of next-swc](https://github.com/vercel/next.js/issues/46989#issuecomment-1486989081).

src/ast_utils.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ pub fn get_local_ident_from_object_pat_prop(
4444
pub fn get_jsx_attr_value_as_string(val: &JSXAttrValue) -> Option<String> {
4545
match val {
4646
// offset="5"
47-
JSXAttrValue::Lit(Lit::Str(Str { value, .. })) => Some(value.to_string()),
47+
JSXAttrValue::Str(Str { value, .. }) => Some(value.to_string_lossy().into_owned()),
4848
// offset={..}
4949
JSXAttrValue::JSXExprContainer(JSXExprContainer {
5050
expr: JSXExpr::Expr(expr),
5151
..
5252
}) => {
5353
match expr.as_ref() {
5454
// offset={"5"}
55-
Expr::Lit(Lit::Str(Str { value, .. })) => Some(value.to_string()),
55+
Expr::Lit(Lit::Str(Str { value, .. })) => {
56+
Some(value.to_string_lossy().into_owned())
57+
}
5658
// offset={5}
5759
Expr::Lit(Lit::Num(Number { value, .. })) => Some(value.to_string()),
5860
_ => None,
@@ -65,7 +67,7 @@ pub fn get_jsx_attr_value_as_string(val: &JSXAttrValue) -> Option<String> {
6567
pub fn get_expr_as_string(val: &Expr) -> Option<String> {
6668
match val {
6769
// "Hello"
68-
Expr::Lit(Lit::Str(Str { value, .. })) => Some(value.to_string()),
70+
Expr::Lit(Lit::Str(Str { value, .. })) => Some(value.to_string_lossy().into_owned()),
6971

7072
// `Hello`
7173
Expr::Tpl(Tpl { quasis, .. }) => {
@@ -136,14 +138,15 @@ pub fn get_object_prop<'a>(props: &'a [PropOrSpread], name: &str) -> Option<&'a
136138
.filter_map(|prop_or_spread| to_key_value_prop(prop_or_spread))
137139
.find(|prop| {
138140
get_prop_key(prop)
139-
.and_then(|key| if key == name { Some(key) } else { None })
140-
.is_some()
141+
.map(|key| key.as_str() == name)
142+
.unwrap_or(false)
141143
})
142144
}
143145

144-
pub fn get_prop_key(prop: &KeyValueProp) -> Option<&Atom> {
146+
pub fn get_prop_key(prop: &KeyValueProp) -> Option<Atom> {
145147
match &prop.key {
146-
PropName::Ident(IdentName { sym, .. }) | PropName::Str(Str { value: sym, .. }) => Some(sym),
148+
PropName::Ident(IdentName { sym, .. }) => Some(sym.clone()),
149+
PropName::Str(Str { value, .. }) => Some(value.to_string_lossy().into_owned().into()),
147150
_ => None,
148151
}
149152
}
@@ -178,7 +181,7 @@ pub fn create_import(source: Atom, imported: IdentName, local: IdentName) -> Mod
178181
})],
179182
src: Box::new(Str {
180183
span: DUMMY_SP,
181-
value: source,
184+
value: source.to_string().into(),
182185
raw: None,
183186
}),
184187
with: None,

src/jsx_visitor.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl TransJSXVisitor<'_> {
110110

111111
match attr_value {
112112
// some="# books"
113-
JSXAttrValue::Lit(Lit::Str(str)) => {
114-
let string: String = str.value.clone().to_string();
113+
JSXAttrValue::Str(str) => {
114+
let string: String = str.value.to_string_lossy().into_owned();
115115
tokens.push(MsgToken::String(string));
116116
}
117117

@@ -121,8 +121,9 @@ impl TransJSXVisitor<'_> {
121121
}) => {
122122
match exp.as_ref() {
123123
// some={"# books"}
124-
Expr::Lit(Lit::Str(str)) => tokens
125-
.push(MsgToken::String(str.value.clone().to_string())),
124+
Expr::Lit(Lit::Str(str)) => tokens.push(MsgToken::String(
125+
str.value.to_string_lossy().into_owned(),
126+
)),
126127
// some={`# books ${name}`}
127128
Expr::Tpl(tpl) => {
128129
tokens.extend(self.ctx.tokenize_tpl(tpl));
@@ -220,7 +221,8 @@ impl Visit for TransJSXVisitor<'_> {
220221
if let JSXExpr::Expr(exp) = &cont.expr {
221222
match exp.as_ref() {
222223
Expr::Lit(Lit::Str(str)) => {
223-
self.tokens.push(MsgToken::String(str.value.to_string()));
224+
self.tokens
225+
.push(MsgToken::String(str.value.to_string_lossy().into_owned()));
224226
}
225227

226228
// todo write tests and validate

0 commit comments

Comments
 (0)