diff --git a/Cargo.lock b/Cargo.lock index 5318f53176b..8936d67c51a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2884,7 +2884,7 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.60.0" +version = "0.60.1" dependencies = [ "ahash", "dashmap", diff --git a/cspell.json b/cspell.json index 1bf1c627be8..cfc020e4e50 100644 --- a/cspell.json +++ b/cspell.json @@ -25,6 +25,7 @@ "cname", "combinator", "Combinator", + "cond", "Cond", "constness", "corejs", diff --git a/ecmascript/transforms/optimization/Cargo.toml b/ecmascript/transforms/optimization/Cargo.toml index 0df8dd9c94e..e08c65ba07e 100644 --- a/ecmascript/transforms/optimization/Cargo.toml +++ b/ecmascript/transforms/optimization/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_optimization" repository = "https://github.com/swc-project/swc.git" -version = "0.60.0" +version = "0.60.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] diff --git a/ecmascript/transforms/optimization/src/inline_globals.rs b/ecmascript/transforms/optimization/src/inline_globals.rs index 490eb5cf0fa..42f6b346a3b 100644 --- a/ecmascript/transforms/optimization/src/inline_globals.rs +++ b/ecmascript/transforms/optimization/src/inline_globals.rs @@ -68,6 +68,24 @@ impl Parallel for InlineGlobals { impl VisitMut for InlineGlobals { noop_visit_mut_type!(); + fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) { + n.right.visit_mut_with(self); + + match &mut n.left { + PatOrExpr::Expr(l) => { + (&mut **l).visit_mut_children_with(self); + } + PatOrExpr::Pat(l) => match &mut **l { + Pat::Expr(l) => { + (&mut **l).visit_mut_children_with(self); + } + _ => { + l.visit_mut_with(self); + } + }, + } + } + fn visit_mut_expr(&mut self, expr: &mut Expr) { match expr { Expr::Ident(Ident { ref sym, span, .. }) => { @@ -336,4 +354,16 @@ mod tests { "const test = process.env['x']", "const test = 'FOO'" ); + + test!( + Default::default(), + |tester| inline_globals( + envs(tester, &[("x", "BAR")]), + globals(tester, &[]), + Default::default(), + ), + issue_2499_1, + "process.env.x = 'foo'", + "process.env.x = 'foo'" + ); }