Skip to content

Commit

Permalink
Updated SWC to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Jul 15, 2024
1 parent 228cf81 commit c92c81e
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 597 deletions.
281 changes: 93 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "MIT"
name = "swc-plugin-inferno"
repository = "https://github.com/infernojs/swc-plugin-inferno.git"
version = "0.0.21"
version = "0.0.22"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -24,22 +24,20 @@ codegen-units = 1
lto = true
# Optimize for size
opt-level = "s"
# Optimize for performance, this is default, so you don't need to specify it
# opt-level = "z"

# Strip debug symbols
strip = "symbols"

[dependencies]
base64 = "0.22.1"
dashmap = "5.5.3"
dashmap = "6.0.1"
indexmap = "2.2.6"
once_cell = "1.19.0"
rayon = { version = "1.10.0", optional = true }
serde = { version = "1.0.203", features = ["derive"], optional = true }
serde = { version = "1.0.204", features = ["derive"], optional = true }
sha-1 = "=0.10.1"

swc_core = { version = "0.95.2", features = [
swc_core = { version = "0.97.2", features = [
"swc_atoms",
"swc_common",
"swc_ecma_ast",
Expand All @@ -50,13 +48,13 @@ swc_core = { version = "0.95.2", features = [
"ecma_ast",
"common",
] }
swc_ecma_parser = { version = "0.146.1" }
swc_ecma_parser = { version = "0.147.0" }
swc_config = { version = "0.1.14" }

[dev-dependencies]
swc_ecma_codegen = { version = "0.151.0" }
swc_ecma_transforms_compat = { version = "0.166.0" }
swc_ecma_transforms_module = { version = "0.183.0" }
swc_ecma_transforms_testing = { version = "0.143.0" }
swc_ecma_transforms = { version = "0.232.0" }
testing = { version = "0.36.0" }
swc_ecma_codegen = { version = "0.152.0" }
swc_ecma_transforms_compat = { version = "0.167.0" }
swc_ecma_transforms_module = { version = "0.184.0" }
swc_ecma_transforms_testing = { version = "0.144.0" }
swc_ecma_transforms = { version = "0.233.0" }
testing = { version = "0.37.0" }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swc-plugin-inferno",
"version": "0.0.21",
"version": "0.0.22",
"description": "Inferno JSX plugin for SWC `@swc/core`",
"main": "swc_plugin_inferno.wasm",
"files": [
Expand Down
57 changes: 34 additions & 23 deletions src/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_config::merge::Merge;
use swc_core::common::comments::Comments;
use swc_core::common::iter::IdentifyLast;
use swc_core::common::util::take::Take;
use swc_core::common::{FileName, Mark, SourceMap, Span, Spanned, DUMMY_SP};
use swc_core::common::{FileName, Mark, SourceMap, Span, Spanned, DUMMY_SP, SyntaxContext};
use swc_core::ecma::ast::*;
use swc_core::ecma::atoms::{Atom, JsWord};
use swc_core::ecma::utils::{drop_span, prepend_stmt, quote_ident, ExprFactory, StmtLike};
Expand Down Expand Up @@ -53,7 +53,10 @@ pub fn parse_expr_for_jsx(
src: String,
top_level_mark: Mark,
) -> Arc<Box<Expr>> {
let fm = cm.new_source_file(FileName::Custom(format!("<jsx-config-{}.js>", name)), src);
let fm = cm.new_source_file(
FileName::Custom(format!("<jsx-config-{}.js>", name)).into(),
src
);

parse_file_as_expr(
&fm,
Expand Down Expand Up @@ -86,7 +89,7 @@ pub fn parse_expr_for_jsx(
fn apply_mark(e: &mut Expr, mark: Mark) {
match e {
Expr::Ident(i) => {
i.span = i.span.apply_mark(mark);
i.ctxt = i.ctxt.apply_mark(mark);
}
Expr::Member(MemberExpr { obj, .. }) => {
apply_mark(obj, mark);
Expand Down Expand Up @@ -138,7 +141,7 @@ fn merge_imports(
.specifiers
.push(ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: quote_ident!(*import_to_add),
local: quote_ident!(*import_to_add).into(),
imported: None,
is_type_only: false,
}))
Expand Down Expand Up @@ -285,7 +288,7 @@ where

let fragment = self
.import_create_fragment
.get_or_insert_with(|| quote_ident!("createFragment"))
.get_or_insert_with(|| quote_ident!("createFragment").into())
.clone();

let mut children_requires_normalization: bool = false;
Expand Down Expand Up @@ -314,11 +317,11 @@ where
span: DUMMY_SP,
callee: self
.import_create_text_vnode
.get_or_insert_with(|| quote_ident!("createTextVNode"))
.get_or_insert_with(|| quote_ident!("createTextVNode").into())
.clone()
.as_callee(),
args: vec![s.as_arg()],
type_args: Default::default(),
..Default::default()
})),
}
}
Expand Down Expand Up @@ -376,6 +379,7 @@ where
callee: fragment.as_callee(),
args: create_fragment_vnode_args(children, false, child_flags as u16, None, None),
type_args: None,
..Default::default()
})
}

Expand All @@ -399,7 +403,7 @@ where
if ident.sym == "Fragment" {
vnode_kind = VNodeType::Fragment;
mut_flags = VNodeFlags::ComponentUnknown as u16;
name_expr = Expr::Ident(Ident::new("createFragment".into(), ident.span));
name_expr = Expr::Ident(Ident::new("createFragment".into(), ident.span.into(), Default::default()));
} else {
vnode_kind = Component;
mut_flags = VNodeFlags::ComponentUnknown as u16;
Expand All @@ -424,7 +428,7 @@ where

return Expr::Invalid(Invalid { span: DUMMY_SP });
}
JSXElementName::JSXMemberExpr(JSXMemberExpr { obj, prop }) => {
JSXElementName::JSXMemberExpr(JSXMemberExpr { obj, prop, .. }) => {
vnode_kind = Component;
mut_flags = VNodeFlags::ComponentUnknown as u16;

Expand Down Expand Up @@ -520,9 +524,9 @@ where
.props
.push(PropOrSpread::Prop(Box::new(Prop::KeyValue(
KeyValueProp {
key: PropName::Ident(Ident::new(
key: PropName::Ident(IdentName::new(
"onDblClick".into(),
span,
span
)),
value: match attr.value {
Some(v) => jsx_attr_value_to_expr(v)
Expand Down Expand Up @@ -688,10 +692,9 @@ where
value: converted_sym.into(),
})
} else {
PropName::Ident(Ident {
PropName::Ident(IdentName {
span: i.span,
sym: converted_sym.into(),
optional: i.optional,
sym: converted_sym.into()
})
};

Expand All @@ -702,7 +705,7 @@ where
value,
}))));
}
JSXAttrName::JSXNamespacedName(JSXNamespacedName { ns, name }) => {
JSXAttrName::JSXNamespacedName(JSXNamespacedName { ns, name, .. }) => {
let value = match attr.value {
Some(v) => {
jsx_attr_value_to_expr(v).expect("empty expression container?")
Expand Down Expand Up @@ -767,9 +770,10 @@ where
spread: None,
expr: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
ctxt: SyntaxContext::empty().apply_mark(self.unresolved_mark),
callee: self
.import_create_text_vnode
.get_or_insert_with(|| quote_ident!("createTextVNode"))
.get_or_insert_with(|| quote_ident!("createTextVNode").into())
.clone()
.as_callee(),
args: vec![s.as_arg()],
Expand Down Expand Up @@ -832,10 +836,11 @@ where
spread: None,
expr: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
ctxt: SyntaxContext::empty().apply_mark(self.unresolved_mark),
callee: self
.import_create_text_vnode
.get_or_insert_with(|| {
quote_ident!("createTextVNode")
quote_ident!("createTextVNode").into()
})
.clone()
.as_callee(),
Expand Down Expand Up @@ -963,15 +968,15 @@ where

let create_method = if vnode_kind == Component {
self.import_create_component
.get_or_insert_with(|| quote_ident!("createComponentVNode"))
.get_or_insert_with(|| quote_ident!("createComponentVNode").into())
.clone()
} else if vnode_kind == VNodeType::Element {
self.import_create_vnode
.get_or_insert_with(|| quote_ident!("createVNode"))
.get_or_insert_with(|| quote_ident!("createVNode").into())
.clone()
} else {
self.import_create_fragment
.get_or_insert_with(|| quote_ident!("createFragment"))
.get_or_insert_with(|| quote_ident!("createFragment").into())
.clone()
};

Expand Down Expand Up @@ -1016,6 +1021,7 @@ where

let create_expr = Expr::Call(CallExpr {
span,
ctxt: SyntaxContext::empty().apply_mark(self.unresolved_mark),
callee: create_method.as_callee(),
args: create_method_args,
type_args: Default::default(),
Expand All @@ -1024,9 +1030,10 @@ where
if needs_normalization {
return Expr::Call(CallExpr {
span,
ctxt: SyntaxContext::empty().apply_mark(self.unresolved_mark),
callee: self
.import_normalize_props
.get_or_insert_with(|| quote_ident!("normalizeProps"))
.get_or_insert_with(|| quote_ident!("normalizeProps").into())
.clone()
.as_callee(),
args: vec![create_expr.as_arg()],
Expand Down Expand Up @@ -1354,7 +1361,7 @@ where
.map(|imported| {
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: quote_ident!(imported),
local: quote_ident!(imported).into(),
imported: None,
is_type_only: false,
})
Expand Down Expand Up @@ -1393,6 +1400,7 @@ where
fn add_require(imports: Vec<&str>, src: &str, unresolved_mark: Mark) -> Stmt {
Stmt::Decl(Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
kind: VarDeclKind::Const,
declare: false,
decls: vec![VarDeclarator {
Expand All @@ -1407,6 +1415,7 @@ fn add_require(imports: Vec<&str>, src: &str, unresolved_mark: Mark) -> Stmt {
key: BindingIdent {
id: Ident {
span: DUMMY_SP,
ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
sym: imported.into(),
optional: false,
},
Expand All @@ -1422,10 +1431,12 @@ fn add_require(imports: Vec<&str>, src: &str, unresolved_mark: Mark) -> Stmt {
// require('inferno')
init: Some(Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
callee: Callee::Expr(Box::new(Expr::Ident(Ident {
span: DUMMY_SP.apply_mark(unresolved_mark),
ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
sym: "require".into(),
optional: false,
..Default::default()
}))),
args: vec![ExprOrSpread {
spread: None,
Expand Down
Loading

0 comments on commit c92c81e

Please sign in to comment.