Skip to content

Commit 6701909

Browse files
authored
build: Update swc_core to v0.90.7 (#7272)
### Description Update swc crates to apply swc-project/swc#8532 and other bugfixes ### Testing Instructions next.js counterpart: vercel/next.js#61662 Closes PACK-2390
1 parent e7afa8d commit 6701909

File tree

12 files changed

+604
-607
lines changed

12 files changed

+604
-607
lines changed

Cargo.lock

+454-421
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ strip = true
9494
[workspace.dependencies]
9595
async-recursion = "1.0.2"
9696
# Keep consistent with preset_env_base through swc_core
97-
browserslist-rs = { version = "0.14.0" }
97+
browserslist-rs = { version = "0.15.0" }
9898
miette = { version = "5.10.0", features = ["fancy"] }
99-
mdxjs = "0.1.22"
100-
modularize_imports = { version = "0.68.2" }
101-
styled_components = { version = "0.96.3" }
102-
styled_jsx = { version = "0.73.4" }
103-
swc_core = { version = "0.89.6", features = [
99+
mdxjs = "0.1.23"
100+
modularize_imports = { version = "0.68.5" }
101+
styled_components = { version = "0.96.6" }
102+
styled_jsx = { version = "0.73.7" }
103+
swc_core = { version = "0.90.7", features = [
104104
"ecma_loader_lru",
105105
"ecma_loader_parking_lot",
106106
] }
107-
swc_emotion = { version = "0.72.2" }
108-
swc_relay = { version = "0.44.2" }
109-
testing = { version = "0.35.16" }
107+
swc_emotion = { version = "0.72.6" }
108+
swc_relay = { version = "0.44.5" }
109+
testing = { version = "0.35.18" }
110110

111111
auto-hash-map = { path = "crates/turbo-tasks-auto-hash-map" }
112112
node-file-trace = { path = "crates/node-file-trace", default-features = false }

crates/turbopack-ecmascript/src/analyzer/graph.rs

+33-19
Original file line numberDiff line numberDiff line change
@@ -1006,21 +1006,25 @@ impl VisitAstPath for Analyzer<'_> {
10061006
{
10071007
let mut ast_path =
10081008
ast_path.with_guard(AstParentNodeRef::AssignExpr(n, AssignExprField::Left));
1009-
match &n.left {
1010-
PatOrExpr::Expr(expr) => {
1011-
if let Some(key) = expr.as_ident() {
1009+
1010+
match n.op {
1011+
AssignOp::Assign => {
1012+
self.current_value = Some(self.eval_context.eval(&n.right));
1013+
n.left.visit_children_with_path(self, &mut ast_path);
1014+
self.current_value = None;
1015+
}
1016+
1017+
_ => {
1018+
if let Some(key) = n.left.as_ident() {
10121019
let value = match n.op {
1013-
AssignOp::Assign => unreachable!(
1014-
"AssignOp::Assign will never have an expression in n.left"
1015-
),
10161020
AssignOp::AndAssign | AssignOp::OrAssign | AssignOp::NullishAssign => {
10171021
let right = self.eval_context.eval(&n.right);
10181022
// We can handle the right value as alternative to the existing
10191023
// value
10201024
Some(right)
10211025
}
10221026
AssignOp::AddAssign => {
1023-
let left = self.eval_context.eval(expr);
1027+
let left = self.eval_context.eval(&Expr::Ident(key.clone()));
10241028
let right = self.eval_context.eval(&n.right);
10251029
Some(JsValue::add(vec![left, right]))
10261030
}
@@ -1030,18 +1034,9 @@ impl VisitAstPath for Analyzer<'_> {
10301034
self.add_value(key.to_id(), value);
10311035
}
10321036
}
1033-
1034-
let mut ast_path = ast_path
1035-
.with_guard(AstParentNodeRef::PatOrExpr(&n.left, PatOrExprField::Expr));
1036-
self.visit_expr(expr, &mut ast_path);
1037-
}
1038-
PatOrExpr::Pat(pat) => {
1039-
debug_assert!(n.op == AssignOp::Assign);
1040-
let mut ast_path = ast_path
1041-
.with_guard(AstParentNodeRef::PatOrExpr(&n.left, PatOrExprField::Pat));
1042-
self.current_value = Some(self.eval_context.eval(&n.right));
1043-
self.visit_pat(pat, &mut ast_path);
1044-
self.current_value = None;
1037+
if n.left.as_ident().is_none() {
1038+
n.left.visit_children_with_path(self, &mut ast_path);
1039+
}
10451040
}
10461041
}
10471042
}
@@ -1415,6 +1410,25 @@ impl VisitAstPath for Analyzer<'_> {
14151410
}
14161411
}
14171412

1413+
fn visit_simple_assign_target<'ast: 'r, 'r>(
1414+
&mut self,
1415+
n: &'ast SimpleAssignTarget,
1416+
ast_path: &mut swc_core::ecma::visit::AstNodePath<'r>,
1417+
) {
1418+
let value = self.current_value.take();
1419+
if let SimpleAssignTarget::Ident(i) = n {
1420+
self.add_value(
1421+
i.to_id(),
1422+
value.unwrap_or_else(|| {
1423+
JsValue::unknown(JsValue::Variable(i.to_id()), false, "pattern without value")
1424+
}),
1425+
);
1426+
return;
1427+
}
1428+
1429+
n.visit_children_with_path(self, ast_path);
1430+
}
1431+
14181432
fn visit_pat<'ast: 'r, 'r>(
14191433
&mut self,
14201434
pat: &'ast Pat,

crates/turbopack-ecmascript/src/references/async_module.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use indexmap::IndexSet;
33
use serde::{Deserialize, Serialize};
44
use swc_core::{
55
common::DUMMY_SP,
6-
ecma::ast::{ArrayLit, ArrayPat, Expr, Ident, Pat, Program},
6+
ecma::ast::{ArrayLit, ArrayPat, Expr, Ident, Program},
77
quote,
88
};
99
use turbo_tasks::{trace::TraceRawVcs, TryFlatJoinIterExt, TryJoinIterExt, Vc};
@@ -213,15 +213,15 @@ fn add_async_dependency_handler(program: &mut Program, idents: &IndexSet<String>
213213
let stmt = quote!(
214214
"($deps = __turbopack_async_dependencies__.then ? (await \
215215
__turbopack_async_dependencies__)() : __turbopack_async_dependencies__);" as Stmt,
216-
deps: Pat = Pat::Array(ArrayPat {
216+
deps: AssignTarget = ArrayPat {
217217
span: DUMMY_SP,
218218
elems: idents
219219
.into_iter()
220220
.map(|ident| { Some(ident.into()) })
221221
.collect(),
222222
optional: false,
223223
type_ann: None,
224-
}),
224+
}.into(),
225225
);
226226

227227
insert_hoisted_stmt(program, stmt);

crates/turbopack-ecmascript/src/references/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use swc_core::{
4242
ecma::{
4343
ast::*,
4444
visit::{
45-
fields::{AssignExprField, ExprField, PatField, PatOrExprField},
45+
fields::{AssignExprField, AssignTargetField, SimpleAssignTargetField},
4646
AstParentKind, AstParentNodeRef, VisitAstPath, VisitWithPath,
4747
},
4848
},
@@ -1844,9 +1844,8 @@ async fn handle_free_var_reference(
18441844
[
18451845
..,
18461846
AstParentKind::AssignExpr(AssignExprField::Left),
1847-
AstParentKind::PatOrExpr(PatOrExprField::Pat),
1848-
AstParentKind::Pat(PatField::Expr),
1849-
AstParentKind::Expr(ExprField::Member),
1847+
AstParentKind::AssignTarget(AssignTargetField::Simple),
1848+
AstParentKind::SimpleAssignTarget(SimpleAssignTargetField::Member),
18501849
]
18511850
) {
18521851
return Ok(false);

crates/turbopack-ecmascript/src/tree_shake/util.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use indexmap::IndexSet;
44
use rustc_hash::FxHasher;
55
use swc_core::ecma::{
66
ast::{
7-
BlockStmtOrExpr, Constructor, Expr, Function, Id, Ident, MemberProp, Pat, PatOrExpr,
7+
AssignTarget, BlockStmtOrExpr, Constructor, Expr, Function, Id, Ident, MemberProp, Pat,
88
PropName,
99
},
1010
visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith},
@@ -35,6 +35,12 @@ impl IdentUsageCollector {
3535
}
3636

3737
impl Visit for IdentUsageCollector {
38+
fn visit_assign_target(&mut self, n: &AssignTarget) {
39+
self.with_mode(Mode::Write, |this| {
40+
n.visit_children_with(this);
41+
})
42+
}
43+
3844
fn visit_block_stmt_or_expr(&mut self, n: &BlockStmtOrExpr) {
3945
if self.ignore_nested {
4046
return;
@@ -88,17 +94,6 @@ impl Visit for IdentUsageCollector {
8894
})
8995
}
9096

91-
fn visit_pat_or_expr(&mut self, n: &PatOrExpr) {
92-
if let PatOrExpr::Expr(e) = n {
93-
self.with_mode(Mode::Write, |this| {
94-
// Skip `visit_expr`
95-
e.visit_children_with(this);
96-
})
97-
} else {
98-
n.visit_children_with(self);
99-
}
100-
}
101-
10297
fn visit_prop_name(&mut self, n: &PropName) {
10398
if let PropName::Computed(..) = n {
10499
n.visit_children_with(self);
@@ -136,6 +131,12 @@ impl CapturedIdCollector {
136131
}
137132

138133
impl Visit for CapturedIdCollector {
134+
fn visit_assign_target(&mut self, n: &AssignTarget) {
135+
self.with_mode(Mode::Write, |this| {
136+
n.visit_children_with(this);
137+
})
138+
}
139+
139140
fn visit_block_stmt_or_expr(&mut self, n: &BlockStmtOrExpr) {
140141
self.with_nested(|this| {
141142
n.visit_children_with(this);
@@ -181,17 +182,6 @@ impl Visit for CapturedIdCollector {
181182
})
182183
}
183184

184-
fn visit_pat_or_expr(&mut self, n: &PatOrExpr) {
185-
if let PatOrExpr::Expr(e) = n {
186-
self.with_mode(Mode::Write, |this| {
187-
// Skip `visit_expr`
188-
e.visit_children_with(this);
189-
})
190-
} else {
191-
n.visit_children_with(self);
192-
}
193-
}
194-
195185
fn visit_prop_name(&mut self, n: &PropName) {
196186
if let PropName::Computed(..) = n {
197187
n.visit_children_with(self);

crates/turbopack-ecmascript/src/webpack/parse.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use swc_core::{
55
common::GLOBALS,
66
ecma::{
77
ast::{
8-
ArrowExpr, AssignOp, BinExpr, BinaryOp, CallExpr, Callee, Expr, ExprOrSpread, ExprStmt,
9-
FnExpr, Lit, Module, ModuleItem, Program, Script, Stmt,
8+
ArrowExpr, AssignOp, AssignTarget, BinExpr, BinaryOp, CallExpr, Callee, Expr,
9+
ExprOrSpread, ExprStmt, FnExpr, Lit, Module, ModuleItem, Program, Script,
10+
SimpleAssignTarget, Stmt,
1011
},
1112
visit::{Visit, VisitWith},
1213
},
@@ -77,6 +78,23 @@ fn is_webpack_require_decl(stmt: &Stmt) -> bool {
7778
false
7879
}
7980

81+
fn get_assign_target_identifier(expr: &AssignTarget) -> Option<Cow<'_, str>> {
82+
match expr.as_simple()? {
83+
SimpleAssignTarget::Ident(ident) => Some(Cow::Borrowed(&*ident.sym)),
84+
SimpleAssignTarget::Member(member) => {
85+
if let Some(obj_name) = get_expr_identifier(&member.obj) {
86+
if let Some(ident) = member.prop.as_ident() {
87+
return Some(Cow::Owned(obj_name.into_owned() + "." + &*ident.sym));
88+
}
89+
}
90+
None
91+
}
92+
SimpleAssignTarget::Paren(p) => get_expr_identifier(&p.expr),
93+
94+
_ => None,
95+
}
96+
}
97+
8098
fn get_expr_identifier(expr: &Expr) -> Option<Cow<'_, str>> {
8199
let expr = unparen(expr);
82100
if let Some(ident) = expr.as_ident() {
@@ -102,11 +120,9 @@ fn get_assignment<'a>(stmts: &'a Vec<Stmt>, property: &str) -> Option<&'a Expr>
102120
if let Some(expr_stmt) = stmt.as_expr() {
103121
if let Some(assign) = unparen(&expr_stmt.expr).as_assign() {
104122
if assign.op == AssignOp::Assign {
105-
if let Some(expr) = assign.left.as_expr() {
106-
if let Some(name) = get_expr_identifier(expr) {
107-
if name == property {
108-
return Some(unparen(&assign.right));
109-
}
123+
if let Some(name) = get_assign_target_identifier(&assign.left) {
124+
if name == property {
125+
return Some(unparen(&assign.right));
110126
}
111127
}
112128
}

crates/turbopack-ecmascript/tests/analyzer/graph/md5-reduced/graph-effects.snapshot

+12-21
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
AssignExpr(
5050
Left,
5151
),
52-
PatOrExpr(
53-
Expr,
52+
AssignTarget(
53+
Simple,
5454
),
55-
Expr(
55+
SimpleAssignTarget(
5656
Member,
5757
),
5858
],
@@ -129,13 +129,10 @@
129129
AssignExpr(
130130
Left,
131131
),
132-
PatOrExpr(
133-
Pat,
134-
),
135-
Pat(
136-
Expr,
132+
AssignTarget(
133+
Simple,
137134
),
138-
Expr(
135+
SimpleAssignTarget(
139136
Member,
140137
),
141138
],
@@ -5403,13 +5400,10 @@
54035400
AssignExpr(
54045401
Left,
54055402
),
5406-
PatOrExpr(
5407-
Pat,
5403+
AssignTarget(
5404+
Simple,
54085405
),
5409-
Pat(
5410-
Expr,
5411-
),
5412-
Expr(
5406+
SimpleAssignTarget(
54135407
Member,
54145408
),
54155409
],
@@ -5449,13 +5443,10 @@
54495443
AssignExpr(
54505444
Left,
54515445
),
5452-
PatOrExpr(
5453-
Pat,
5446+
AssignTarget(
5447+
Simple,
54545448
),
5455-
Pat(
5456-
Expr,
5457-
),
5458-
Expr(
5449+
SimpleAssignTarget(
54595450
Member,
54605451
),
54615452
MemberExpr(

0 commit comments

Comments
 (0)