Skip to content

Commit

Permalink
chore: Update swc (#40832)
Browse files Browse the repository at this point in the history
This PR update swc crates to
swc-project/swc@8a5ed1e


Noticeable changes include

 - TS 4.9 support.
 - Huge performance improvement (of every api).
  • Loading branch information
kdy1 committed Sep 23, 2022
1 parent cc7fd2c commit b68f783
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 189 deletions.
193 changes: 97 additions & 96 deletions packages/next-swc/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -28,7 +28,7 @@ styled_jsx = {path="../styled_jsx"}
modularize_imports = {path="../modularize_imports"}
tracing = { version = "0.1.32", features = ["release_max_level_info"] }

swc_core = { version = "0.23.24", features = [
swc_core = { version = "0.26.0", features = [
"common_concurrent",
"ecma_ast",
"ecma_visit",
Expand All @@ -48,6 +48,6 @@ swc_core = { version = "0.23.24", features = [
] }

[dev-dependencies]
swc_core = { version = "0.23.24", features = ["testing_transform"] }
testing = "0.30.7"
swc_core = { version = "0.26.0", features = ["testing_transform"] }
testing = "0.30.10"
walkdir = "2.3.2"
6 changes: 3 additions & 3 deletions packages/next-swc/crates/core/src/hook_optimizer.rs
Expand Up @@ -41,7 +41,7 @@ impl Fold for HookOptimizer {
fn fold_decl(&mut self, node: Decl) -> Decl {
let node = node.fold_children_with(self);
match node {
Decl::Var(VarDecl {
Decl::Var(box VarDecl {
decls,
span,
kind,
Expand All @@ -52,12 +52,12 @@ impl Fold for HookOptimizer {
new_decls.push(self.get_decl(decl));
}

Decl::Var(VarDecl {
Decl::Var(Box::new(VarDecl {
decls: new_decls,
span,
kind,
declare,
})
}))
}
_ => node,
}
Expand Down
1 change: 1 addition & 0 deletions packages/next-swc/crates/core/src/lib.rs
Expand Up @@ -28,6 +28,7 @@ DEALINGS IN THE SOFTWARE.

#![recursion_limit = "2048"]
#![deny(clippy::all)]
#![feature(box_patterns)]

use auto_cjs::contains_cjs;
use either::Either;
Expand Down
Expand Up @@ -46,15 +46,15 @@ impl<'a> FontImportsGenerator<'a> {
values.append(&mut json_values);

return Some(ImportDecl {
src: Str {
src: Box::new(Str {
value: JsWord::from(format!(
"{}?{}",
font_function.loader,
values.join(";")
)),
raw: None,
span: DUMMY_SP,
},
}),
specifiers: vec![],
type_only: false,
asserts: None,
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/src/next_ssg.rs
Expand Up @@ -495,12 +495,12 @@ impl Fold for NextSsg {
if let Some(var) = var.take() {
new.push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
span: DUMMY_SP,
decl: Decl::Var(VarDecl {
decl: Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: Default::default(),
decls: vec![var],
}),
})),
})))
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/src/page_config.rs
Expand Up @@ -43,7 +43,7 @@ impl Fold for PageConfig {
true => String::from("mock_timestamp"),
false => Utc::now().timestamp().to_string(),
};
return vec![ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
return vec![ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
decls: vec![VarDeclarator {
name: Pat::Ident(BindingIdent {
id: Ident {
Expand All @@ -64,7 +64,7 @@ impl Fold for PageConfig {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
})))];
}))))];
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/src/react_server_components.rs
Expand Up @@ -161,7 +161,7 @@ impl<C: Comments> ReactServerComponents<C> {
prepend_stmts(
&mut module.body,
vec![
ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
decls: vec![VarDeclarator {
Expand All @@ -185,7 +185,7 @@ impl<C: Comments> ReactServerComponents<C> {
definite: false,
}],
declare: false,
}))),
})))),
ModuleItem::Stmt(Stmt::Expr(ExprStmt {
span: DUMMY_SP,
expr: Box::new(Expr::Assign(AssignExpr {
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/emotion/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ description = "AST Transforms for emotion"
license = "Apache-2.0"
name = "swc_emotion"
repository = "https://github.com/vercel/next.js.git"
version = "0.20.0"
version = "0.21.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -19,9 +19,9 @@ regex = "1.5"
serde = "1"
sourcemap = "6.0.1"
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
swc_core = { version = "0.23.24", features = ["common", "ecma_ast","ecma_codegen", "ecma_utils", "ecma_visit", "trace_macro"] }
swc_core = { version = "0.26.0", features = ["common", "ecma_ast","ecma_codegen", "ecma_utils", "ecma_visit", "trace_macro"] }

[dev-dependencies]
swc_core = { version = "0.23.24", features = ["testing_transform", "ecma_transforms_react"] }
testing = "0.30.7"
swc_core = { version = "0.26.0", features = ["testing_transform", "ecma_transforms_react"] }
testing = "0.30.10"
serde_json = "1"
8 changes: 4 additions & 4 deletions packages/next-swc/crates/modularize_imports/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
license = "Apache-2.0"
name = "modularize_imports"
repository = "https://github.com/vercel/next.js.git"
version = "0.18.0"
version = "0.19.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -15,8 +15,8 @@ handlebars = "4.2.1"
once_cell = "1.13.0"
regex = "1.5"
serde = "1"
swc_core = { version = "0.23.24", features = ["cached", "ecma_ast", "ecma_visit"] }
swc_core = { version = "0.26.0", features = ["cached", "ecma_ast", "ecma_visit"] }

[dev-dependencies]
swc_core = { version = "0.23.24", features = ["testing_transform"] }
testing = "0.30.7"
swc_core = { version = "0.26.0", features = ["testing_transform"] }
testing = "0.30.10"
2 changes: 1 addition & 1 deletion packages/next-swc/crates/modularize_imports/src/lib.rs
Expand Up @@ -91,7 +91,7 @@ impl<'a> Rewriter<'a> {
};
out.push(ImportDecl {
specifiers: vec![specifier],
src: Str::from(new_path.as_ref()),
src: Box::new(Str::from(new_path.as_ref())),
span: old_decl.span,
type_only: false,
asserts: None,
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/napi/Cargo.toml
Expand Up @@ -30,7 +30,7 @@ next-swc = {version = "0.0.0", path = "../core"}
once_cell = "1.13.0"
serde = "1"
serde_json = "1"
swc_core = { version = "0.23.24", features = [
swc_core = { version = "0.26.0", features = [
"allocator_node",
"base_concurrent", # concurrent?
"common_concurrent",
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/styled_components/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "styled_components"
repository = "https://github.com/vercel/next.js.git"
version = "0.43.0"
version = "0.44.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -16,7 +16,7 @@ once_cell = "1.13.0"
regex = {version = "1.5.4", features = ["std", "perf"], default-features = false}
serde = {version = "1.0.130", features = ["derive"]}
tracing = "0.1.32"
swc_core = { version = "0.23.24", features = [
swc_core = { version = "0.26.0", features = [
"common",
"ecma_ast",
"ecma_utils",
Expand All @@ -25,8 +25,8 @@ swc_core = { version = "0.23.24", features = [

[dev-dependencies]
serde_json = "1"
testing = "0.30.7"
swc_core = { version = "0.23.24", features = [
testing = "0.30.10"
swc_core = { version = "0.26.0", features = [
"ecma_parser",
"ecma_transforms",
"testing_transform"
Expand Down
Expand Up @@ -314,12 +314,12 @@ impl VisitMut for TranspileCssProp {
}),
definite: false,
};
let stmt = Stmt::Decl(Decl::Var(VarDecl {
let stmt = Stmt::Decl(Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: false,
decls: vec![var],
}));
})));
match inject_after {
Some(injector) => {
let id = injector.to_id();
Expand Down Expand Up @@ -375,11 +375,11 @@ impl VisitMut for TranspileCssProp {
ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
span: DUMMY_SP,
specifiers: vec![specifier],
src: Str {
src: Box::new(Str {
span: DUMMY_SP,
value: "styled-components".into(),
raw: None,
},
}),
type_only: Default::default(),
asserts: Default::default(),
})),
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/styled_jsx/Cargo.toml
Expand Up @@ -5,15 +5,15 @@ edition = "2018"
license = "Apache-2.0"
name = "styled_jsx"
repository = "https://github.com/vercel/next.js.git"
version = "0.18.0"
version = "0.19.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
easy-error = "1.0.0"
tracing = "0.1.32"

swc_core = { version = "0.23.24", features = [
swc_core = { version = "0.26.0", features = [
"common",
"css_ast",
"css_codegen",
Expand All @@ -27,7 +27,7 @@ swc_core = { version = "0.23.24", features = [
] }

[dev-dependencies]
testing = "0.30.7"
swc_core = { version = "0.23.24", features = [
testing = "0.30.10"
swc_core = { version = "0.26.0", features = [
"testing_transform"
] }
8 changes: 5 additions & 3 deletions packages/next-swc/crates/styled_jsx/src/lib.rs
@@ -1,3 +1,5 @@
#![feature(box_patterns)]

use easy_error::{bail, Error};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -320,7 +322,7 @@ impl Fold for StyledJSXTransformer {
for item in items {
let new_item = item.fold_children_with(self);
if let Some((default_ident, default_expr)) = &self.add_default_decl {
new_items.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
new_items.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
kind: VarDeclKind::Const,
declare: false,
decls: vec![VarDeclarator {
Expand All @@ -337,7 +339,7 @@ impl Fold for StyledJSXTransformer {
span: DUMMY_SP,
}],
span: DUMMY_SP,
}))));
})))));
self.add_default_decl = None;
if let Some(add_hash) = self.add_hash.take() {
new_items.push(ModuleItem::Stmt(add_hash_statement(add_hash)));
Expand Down Expand Up @@ -921,7 +923,7 @@ fn add_hash_statement((id, hash): (Id, String)) -> Stmt {

fn is_styled_css_import(item: &ModuleItem) -> bool {
if let ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
src: Str { value, .. },
src: box Str { value, .. },
..
})) = item
{
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/styled_jsx/src/utils.rs
Expand Up @@ -307,11 +307,11 @@ pub fn styled_jsx_import_decl(style_import_name: &str) -> ModuleItem {
},
span: DUMMY_SP,
})],
src: Str {
src: Box::new(Str {
span: DUMMY_SP,
value: "styled-jsx/style".into(),
raw: None,
},
}),
}))
}

Expand Down

0 comments on commit b68f783

Please sign in to comment.