Skip to content

Commit

Permalink
Update swc (#36477)
Browse files Browse the repository at this point in the history
* Update

* Update swc

* Update again

* Fix

* log

* Fix

* clippy

* Update

* Fix
  • Loading branch information
kdy1 committed Apr 27, 2022
1 parent 04e887b commit f2c3ef8
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 89 deletions.
83 changes: 43 additions & 40 deletions packages/next-swc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/next-swc/crates/core/Cargo.toml
Expand Up @@ -21,16 +21,16 @@ swc_emotion = {path="../emotion"}
styled_components = {path="../styled_components"}
styled_jsx = {path="../styled_jsx"}
modularize_imports = {path="../modularize_imports"}
swc = "0.170.0"
swc = "0.172.1"
swc_atoms = "0.2.11"
swc_common = { version = "0.17.24", features = ["concurrent", "sourcemap"] }
swc_common = { version = "0.17.25", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.29.1", features = ["node", "lru"] }
swc_ecmascript = { version = "0.148.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_ecmascript = { version = "0.150.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_off"] }


[dev-dependencies]
swc_ecma_transforms_testing = "0.81.0"
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
walkdir = "2.3.2"
6 changes: 3 additions & 3 deletions packages/next-swc/crates/emotion/Cargo.toml
Expand Up @@ -19,9 +19,9 @@ regex = "1.5"
serde = "1"
sourcemap = "6.0.1"
swc_atoms = "0.2.11"
swc_common = { version = "0.17.24", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.148.0", features = ["codegen", "utils", "visit"] }
swc_common = { version = "0.17.25", features = ["concurrent", "sourcemap"] }
swc_ecmascript = { version = "0.150.0", features = ["codegen", "utils", "visit"] }

[dev-dependencies]
swc_ecma_transforms_testing = "0.81.0"
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
4 changes: 2 additions & 2 deletions packages/next-swc/crates/modularize_imports/Cargo.toml
Expand Up @@ -15,8 +15,8 @@ once_cell = "1.8.0"
regex = "1.5"
serde = "1"
swc_cached = "0.1.1"
swc_ecmascript = { version = "0.148.0", features = ["visit"] }
swc_ecmascript = { version = "0.150.0", features = ["visit"] }

[dev-dependencies]
swc_ecma_transforms_testing = "0.81.0"
swc_ecma_transforms_testing = "0.82.0"
testing = "0.19.1"
8 changes: 4 additions & 4 deletions packages/next-swc/crates/napi/Cargo.toml
Expand Up @@ -17,12 +17,12 @@ next-swc = {version = "0.0.0", path = "../core"}
once_cell = "1.8.0"
serde = "1"
serde_json = "1"
swc = "0.170.0"
swc = "0.172.1"
swc_atoms = "0.2.11"
swc_bundler = { version = "0.138.0", features = ["concurrent"] }
swc_common = { version = "0.17.24", features = ["concurrent", "sourcemap"] }
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.148.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_ecmascript = { version = "0.150.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.2"

[build-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions packages/next-swc/crates/styled_components/Cargo.toml
Expand Up @@ -15,12 +15,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.24", features = ["concurrent"] }
swc_ecmascript = { version = "0.148.0", features = ["utils", "visit"] }
swc_common = { version = "0.17.25", features = ["concurrent"] }
swc_ecmascript = { version = "0.150.0", features = ["utils", "visit"] }
tracing = "0.1.32"

[dev-dependencies]
serde_json = "1"
swc_ecma_transforms_testing = "0.81.0"
swc_ecmascript = { version = "0.148.0", features = ["parser", "transforms"] }
swc_ecma_transforms_testing = "0.82.0"
swc_ecmascript = { version = "0.150.0", features = ["parser", "transforms"] }
testing = "0.19.1"
30 changes: 15 additions & 15 deletions packages/next-swc/crates/styled_components/src/utils/analyzer.rs
Expand Up @@ -3,7 +3,7 @@ use crate::Config;
use std::{cell::RefCell, rc::Rc};
use swc_ecmascript::{
ast::*,
utils::{ident::IdentLike, ExprExt},
utils::ident::IdentLike,
visit::{as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith},
};

Expand Down Expand Up @@ -69,20 +69,20 @@ impl Visit for Analyzer<'_> {
..
})) = v.init.as_deref()
{
if callee.is_ident_ref_to("require".into())
&& args.len() == 1
&& args[0].spread.is_none()
{
if let Expr::Lit(Lit::Str(v)) = &*args[0].expr {
let is_styled = if self.config.top_level_import_paths.is_empty() {
&*v.value == "styled-components"
|| v.value.starts_with("styled-components/")
} else {
self.config.top_level_import_paths.contains(&v.value)
};

if is_styled {
self.state.styled_required = Some(name.id.to_id());
if let Expr::Ident(callee) = &**callee {
if &*callee.sym == "require" && args.len() == 1 && args[0].spread.is_none() {
if let Expr::Lit(Lit::Str(v)) = &*args[0].expr {
let is_styled = if self.config.top_level_import_paths.is_empty() {
&*v.value == "styled-components"
|| v.value.starts_with("styled-components/")
} else {
self.config.top_level_import_paths.contains(&v.value)
};

if is_styled {
self.state.styled_required = Some(name.id.to_id());
self.state.unresolved_ctxt = Some(callee.span.ctxt);
}
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions packages/next-swc/crates/styled_components/src/utils/mod.rs
Expand Up @@ -3,7 +3,7 @@ use once_cell::sync::Lazy;
use regex::{Captures, Regex};
use std::{borrow::Cow, cell::RefCell};
use swc_atoms::js_word;
use swc_common::collections::AHashMap;
use swc_common::{collections::AHashMap, SyntaxContext};
use swc_ecmascript::{
ast::*,
utils::{ident::IdentLike, Id},
Expand Down Expand Up @@ -59,6 +59,8 @@ pub(crate) fn get_prop_name2(p: &Prop) -> PropName {
pub struct State {
pub(crate) styled_required: Option<Id>,

unresolved_ctxt: Option<SyntaxContext>,

imported_local_name: Option<Id>,
/// Namespace imports
imported_local_ns: Option<Id>,
Expand Down Expand Up @@ -227,11 +229,7 @@ impl State {

let cache_key = cache_identifier.map(|i| i.to_id()).unwrap_or_default();

let ctxt = self
.styled_required
.as_ref()
.map(|v| v.1)
.unwrap_or_default();
let ctxt = self.unresolved_ctxt.unwrap_or_default();

let local_name = if self.styled_required.is_some() {
Some(if name == "default" {
Expand Down

0 comments on commit f2c3ef8

Please sign in to comment.