Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update swc #36745

Merged
merged 18 commits into from May 16, 2022
255 changes: 153 additions & 102 deletions packages/next-swc/Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -21,15 +21,15 @@ swc_emotion = {path="../emotion"}
styled_components = {path="../styled_components"}
styled_jsx = {path="../styled_jsx"}
modularize_imports = {path="../modularize_imports"}
swc = "0.172.1"
swc = "0.180.0"
swc_atoms = "0.2.11"
swc_common = { version = "0.17.25", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.29.1", features = ["node", "lru"] }
swc_ecmascript = { version = "0.150.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_common = { version = "0.18.2", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.30.1", features = ["node", "lru"] }
swc_ecmascript = { version = "0.157.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_cached = "0.1.1"
tracing = { version = "0.1.32", features = ["release_max_level_info"] }

[dev-dependencies]
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
swc_ecma_transforms_testing = "0.87.0"
testing = "0.20.0"
walkdir = "2.3.2"
@@ -1,6 +1,6 @@
use swc_common::errors::HANDLER;
use swc_common::pass::Optional;
use swc_ecmascript::ast::ExportAll;
use swc_ecmascript::utils::HANDLER;
use swc_ecmascript::visit::{noop_fold_type, Fold};

pub fn disallow_re_export_all_in_page(is_page_file: bool) -> impl Fold {
Expand Down
9 changes: 3 additions & 6 deletions packages/next-swc/crates/core/src/next_dynamic.rs
Expand Up @@ -2,17 +2,14 @@ use std::path::{Path, PathBuf};

use pathdiff::diff_paths;
use swc_atoms::js_word;
use swc_common::errors::HANDLER;
use swc_common::{FileName, DUMMY_SP};
use swc_ecmascript::ast::{
ArrayLit, ArrowExpr, BinExpr, BinaryOp, BlockStmtOrExpr, Bool, CallExpr, Callee, Expr,
ExprOrSpread, Ident, ImportDecl, ImportSpecifier, KeyValueProp, Lit, MemberExpr, MemberProp,
Null, ObjectLit, Prop, PropName, PropOrSpread, Str,
ExprOrSpread, Id, Ident, ImportDecl, ImportSpecifier, KeyValueProp, Lit, MemberExpr,
MemberProp, Null, ObjectLit, Prop, PropName, PropOrSpread, Str,
};
use swc_ecmascript::utils::ExprFactory;
use swc_ecmascript::utils::{
ident::{Id, IdentLike},
HANDLER,
};
use swc_ecmascript::visit::{Fold, FoldWith};

pub fn next_dynamic(
Expand Down
7 changes: 2 additions & 5 deletions packages/next-swc/crates/core/src/next_ssg.rs
Expand Up @@ -3,15 +3,12 @@ use fxhash::FxHashSet;
use std::cell::RefCell;
use std::mem::take;
use std::rc::Rc;
use swc_common::errors::HANDLER;
use swc_common::pass::{Repeat, Repeated};
use swc_common::DUMMY_SP;
use swc_ecmascript::ast::*;
use swc_ecmascript::utils::ident::IdentLike;
use swc_ecmascript::visit::FoldWith;
use swc_ecmascript::{
utils::{Id, HANDLER},
visit::{noop_fold_type, Fold},
};
use swc_ecmascript::visit::{noop_fold_type, Fold};

static SSG_EXPORTS: &[&str; 3] = &["getStaticProps", "getStaticPaths", "getServerSideProps"];

Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/core/src/page_config.rs
@@ -1,7 +1,7 @@
use chrono::Utc;
use swc_common::errors::HANDLER;
use swc_common::{Span, DUMMY_SP};
use swc_ecmascript::ast::*;
use swc_ecmascript::utils::HANDLER;
use swc_ecmascript::visit::{Fold, FoldWith};

pub fn page_config(is_development: bool, is_page_file: bool) -> impl Fold {
Expand Down
2 changes: 0 additions & 2 deletions packages/next-swc/crates/core/src/remove_console.rs
Expand Up @@ -3,8 +3,6 @@ use swc_atoms::JsWord;
use swc_common::collections::AHashSet;
use swc_common::DUMMY_SP;
use swc_ecmascript::ast::*;
use swc_ecmascript::utils::ident::IdentLike;
use swc_ecmascript::utils::Id;
use swc_ecmascript::visit::{noop_fold_type, Fold, FoldWith};

use crate::top_level_binding_collector::collect_top_level_decls;
Expand Down
3 changes: 2 additions & 1 deletion packages/next-swc/crates/core/src/shake_exports.rs
@@ -1,6 +1,7 @@
use serde::Deserialize;
use swc_atoms::js_word;
use swc_atoms::JsWord;
use swc_common::Mark;
use swc_ecmascript::ast::*;
use swc_ecmascript::transforms::optimization::simplify::dce::{dce, Config as DCEConfig};
use swc_ecmascript::visit::{Fold, FoldWith};
Expand All @@ -26,7 +27,7 @@ struct ExportShaker {
impl Fold for ExportShaker {
fn fold_module(&mut self, module: Module) -> Module {
let module = module.fold_children_with(self);
module.fold_with(&mut dce(DCEConfig::default()))
module.fold_with(&mut dce(DCEConfig::default(), Mark::new()))
}

fn fold_module_items(&mut self, items: Vec<ModuleItem>) -> Vec<ModuleItem> {
Expand Down
16 changes: 8 additions & 8 deletions packages/next-swc/crates/core/tests/fixture.rs
Expand Up @@ -87,15 +87,15 @@ fn next_ssg_fixture(input: PathBuf) {
tr.cm.clone(),
None,
swc_ecmascript::transforms::react::Options {
next: false,
next: false.into(),
runtime: None,
import_source: "".into(),
pragma: "__jsx".into(),
pragma_frag: "__jsxFrag".into(),
throw_if_namespace: false,
development: false,
use_builtins: true,
use_spread: true,
import_source: Some("".into()),
pragma: Some("__jsx".into()),
pragma_frag: Some("__jsxFrag".into()),
throw_if_namespace: false.into(),
development: false.into(),
use_builtins: true.into(),
use_spread: true.into(),
refresh: Default::default(),
},
top_level_mark,
Expand Down
10 changes: 5 additions & 5 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.4.0"
version = "0.5.0"

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

Expand All @@ -19,11 +19,11 @@ regex = "1.5"
serde = "1"
sourcemap = "6.0.1"
swc_atoms = "0.2.11"
swc_common = { version = "0.17.25", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.150.0", features = ["codegen", "utils", "visit"] }
swc_common = { version = "0.18.2", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.157.0", features = ["codegen", "utils", "visit"] }
swc_trace_macro = "0.1.1"
tracing = { version = "0.1.32", features = ["release_max_level_info"] }

[dev-dependencies]
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
swc_ecma_transforms_testing = "0.87.0"
testing = "0.20.0"
7 changes: 3 additions & 4 deletions packages/next-swc/crates/emotion/src/lib.rs
Expand Up @@ -15,12 +15,11 @@ use swc_ecmascript::ast::{
ArrayLit, CallExpr, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXElementName,
JSXExpr, JSXExprContainer, JSXObject,
};
use swc_ecmascript::utils::ident::IdentLike;
use swc_ecmascript::utils::{ExprFactory, Id};
use swc_ecmascript::utils::ExprFactory;
use swc_ecmascript::{
ast::{
Callee, Expr, ExprOrSpread, Ident, ImportDecl, ImportSpecifier, JSXElement, KeyValueProp,
MemberProp, ObjectLit, Pat, Prop, PropName, PropOrSpread, Tpl, VarDeclarator,
Callee, Expr, ExprOrSpread, Id, Ident, ImportDecl, ImportSpecifier, JSXElement,
KeyValueProp, MemberProp, ObjectLit, Pat, Prop, PropName, PropOrSpread, Tpl, VarDeclarator,
},
codegen::util::SourceMapperExt,
visit::{Fold, FoldWith},
Expand Down
10 changes: 5 additions & 5 deletions packages/next-swc/crates/emotion/tests/fixture.rs
Expand Up @@ -27,12 +27,12 @@ fn next_emotion_fixture(input: PathBuf) {
tr.cm.clone(),
Some(tr.comments.as_ref().clone()),
swc_ecmascript::transforms::react::Options {
next: false,
next: false.into(),
runtime: Some(Runtime::Automatic),
throw_if_namespace: false,
development: false,
use_builtins: true,
use_spread: true,
throw_if_namespace: false.into(),
development: false.into(),
use_builtins: true.into(),
use_spread: true.into(),
..Default::default()
},
top_level_mark,
Expand Down
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.3.0"
version = "0.4.0"

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

Expand All @@ -15,8 +15,8 @@ once_cell = "1.8.0"
regex = "1.5"
serde = "1"
swc_cached = "0.1.1"
swc_ecmascript = { version = "0.150.0", features = ["visit"] }
swc_ecmascript = { version = "0.157.0", features = ["visit"] }

[dev-dependencies]
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
swc_ecma_transforms_testing = "0.87.0"
testing = "0.20.0"
12 changes: 6 additions & 6 deletions packages/next-swc/crates/napi/Cargo.toml
Expand Up @@ -17,13 +17,13 @@ next-swc = {version = "0.0.0", path = "../core"}
once_cell = "1.8.0"
serde = "1"
serde_json = "1"
swc = "0.172.1"
swc = "0.180.0"
swc_atoms = "0.2.11"
swc_bundler = { version = "0.140.0", features = ["concurrent"] }
swc_common = { version = "0.17.25", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.29.1", features = ["node", "lru"] }
swc_ecmascript = { version = "0.150.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.2"
swc_bundler = { version = "0.147.0", features = ["concurrent"] }
swc_common = { version = "0.18.2", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.30.1", features = ["node", "lru"] }
swc_ecmascript = { version = "0.157.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.3"
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.9"
Expand Down
2 changes: 2 additions & 0 deletions packages/next-swc/crates/napi/src/bundle/mod.rs
Expand Up @@ -123,6 +123,8 @@ impl Task for BundleTask {
None,
false,
Some(&comments),
true,
false,
)?;

Ok(code)
Expand Down
12 changes: 6 additions & 6 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.28.0"
version = "0.29.0"

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

Expand All @@ -16,12 +16,12 @@ once_cell = "1.10.0"
regex = {version = "1.5.4", features = ["std", "perf"], default-features = false}
serde = {version = "1.0.130", features = ["derive"]}
swc_atoms = "0.2.11"
swc_common = {version = "0.17.25", features = ["concurrent"]}
swc_ecmascript = {version = "0.150.0", features = ["utils", "visit"]}
swc_common = { version = "0.18.2", features = ["concurrent"] }
swc_ecmascript = { version = "0.157.0", features = ["utils", "visit"] }
tracing = "0.1.32"

[dev-dependencies]
serde_json = "1"
swc_ecma_transforms_testing = "0.82.0"
swc_ecmascript = {version = "0.150.0", features = ["parser", "transforms"]}
testing = "0.19.1"
swc_ecma_transforms_testing = "0.87.0"
swc_ecmascript = { version = "0.157.0", features = ["parser", "transforms"] }
testing = "0.20.0"
Expand Up @@ -3,7 +3,6 @@ use crate::Config;
use std::{cell::RefCell, rc::Rc};
use swc_ecmascript::{
ast::*,
utils::ident::IdentLike,
visit::{as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith},
};

Expand Down
Expand Up @@ -4,10 +4,7 @@ use regex::{Captures, Regex};
use std::{borrow::Cow, cell::RefCell};
use swc_atoms::js_word;
use swc_common::{collections::AHashMap, SyntaxContext};
use swc_ecmascript::{
ast::*,
utils::{ident::IdentLike, Id},
};
use swc_ecmascript::ast::*;

mod analyzer;

Expand Down
@@ -1,10 +1,9 @@
use swc_common::collections::AHashSet;
use swc_ecmascript::{
ast::{
ArrowExpr, ClassDecl, FnDecl, Function, ImportDefaultSpecifier, ImportNamedSpecifier,
ArrowExpr, ClassDecl, FnDecl, Function, Id, ImportDefaultSpecifier, ImportNamedSpecifier,
ImportStarAsSpecifier, ObjectPatProp, Pat, VarDeclarator,
},
utils::{ident::IdentLike, Id},
visit::{noop_visit_type, Visit, VisitWith},
};

Expand Down
Expand Up @@ -13,7 +13,7 @@ use swc_common::{
};
use swc_ecmascript::{
ast::*,
utils::{ident::IdentLike, prepend, private_ident, quote_ident, ExprExt, ExprFactory, Id},
utils::{prepend_stmt, private_ident, quote_ident, ExprFactory},
visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith},
};

Expand Down Expand Up @@ -140,7 +140,12 @@ impl VisitMut for TranspileCssProp {
..
}) => match &mut **v {
Expr::Tpl(..) => *v.take(),
Expr::TaggedTpl(v) if v.tag.is_ident_ref_to("css".into()) => {
Expr::TaggedTpl(v)
if match &*v.tag {
Expr::Ident(i) => &*i.sym == "css",
_ => false,
} =>
{
Expr::Tpl(v.tpl.take())
}
Expr::Object(..) => *v.take(),
Expand Down Expand Up @@ -348,7 +353,7 @@ impl VisitMut for TranspileCssProp {
span: DUMMY_SP,
local: import_name,
});
prepend(
prepend_stmt(
&mut n.body,
ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
span: DUMMY_SP,
Expand Down
14 changes: 7 additions & 7 deletions packages/next-swc/crates/styled_jsx/Cargo.toml
Expand Up @@ -5,18 +5,18 @@ edition = "2018"
license = "Apache-2.0"
name = "styled_jsx"
repository = "https://github.com/vercel/next.js.git"
version = "0.3.0"
version = "0.4.0"

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

[dependencies]
easy-error = "1.0.0"
swc_common = { version = "0.17.25", features = ["concurrent", "sourcemap"] }
swc_css = "0.104.1"
swc_css_prefixer = "0.100.4"
swc_ecmascript = { version = "0.150.0", features = ["parser", "minifier", "utils", "visit"] }
swc_common = { version = "0.18.2", features = ["concurrent", "sourcemap"] }
swc_css = "0.105.0"
swc_css_prefixer = "0.101.0"
swc_ecmascript = { version = "0.157.0", features = ["parser", "minifier", "utils", "visit"] }
tracing = "0.1.32"

[dev-dependencies]
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
swc_ecma_transforms_testing = "0.87.0"
testing = "0.20.0"
9 changes: 3 additions & 6 deletions packages/next-swc/crates/styled_jsx/src/lib.rs
Expand Up @@ -3,17 +3,14 @@ use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::mem::take;
use std::sync::Arc;
use swc_common::errors::HANDLER;
use swc_common::{collections::AHashSet, FileName, SourceMap, Span, DUMMY_SP};
use swc_ecmascript::ast::*;
use swc_ecmascript::minifier::{
eval::{EvalResult, Evaluator},
marks::Marks,
};
use swc_ecmascript::utils::{
collect_decls,
ident::{Id, IdentLike},
prepend, HANDLER,
};
use swc_ecmascript::utils::{collect_decls, prepend_stmt};
use swc_ecmascript::utils::{drop_span, private_ident};
use swc_ecmascript::visit::{Fold, FoldWith};

Expand Down Expand Up @@ -334,7 +331,7 @@ impl Fold for StyledJSXTransformer {
}

if self.file_has_styled_jsx || self.file_has_css_resolve {
prepend(
prepend_stmt(
&mut new_items,
styled_jsx_import_decl(self.style_import_name.as_ref().unwrap()),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/styled_jsx/src/transform_css.rs
@@ -1,6 +1,7 @@
use easy_error::{bail, Error};
use std::panic;
use std::sync::Arc;
use swc_common::errors::HANDLER;
use swc_common::util::take::Take;
use swc_common::{source_map::Pos, BytePos, Span, SyntaxContext, DUMMY_SP};
use swc_common::{SourceMap, Spanned};
Expand All @@ -15,7 +16,6 @@ use swc_css::visit::{VisitMut, VisitMutWith};
use swc_css_prefixer::prefixer;
use swc_ecmascript::ast::{Expr, Tpl, TplElement};
use swc_ecmascript::parser::StringInput;
use swc_ecmascript::utils::HANDLER;
use tracing::{debug, trace};

use super::{hash_string, string_literal_expr, LocalStyle};
Expand Down