mirror of
https://github.com/swc-project/swc.git
synced 2025-01-08 23:10:13 +03:00
fix(es/transforms/optimization): Fix inline_globals
(#2524)
swc_ecma_transforms_optimization: - `inline_globals`: Skip assignment to `process.env.FOO`. (#2499)
This commit is contained in:
parent
cead404a53
commit
709b3c7cd6
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2884,7 +2884,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "swc_ecma_transforms_optimization"
|
name = "swc_ecma_transforms_optimization"
|
||||||
version = "0.60.0"
|
version = "0.60.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
"cname",
|
"cname",
|
||||||
"combinator",
|
"combinator",
|
||||||
"Combinator",
|
"Combinator",
|
||||||
|
"cond",
|
||||||
"Cond",
|
"Cond",
|
||||||
"constness",
|
"constness",
|
||||||
"corejs",
|
"corejs",
|
||||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
|||||||
license = "Apache-2.0/MIT"
|
license = "Apache-2.0/MIT"
|
||||||
name = "swc_ecma_transforms_optimization"
|
name = "swc_ecma_transforms_optimization"
|
||||||
repository = "https://github.com/swc-project/swc.git"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -68,6 +68,24 @@ impl Parallel for InlineGlobals {
|
|||||||
impl VisitMut for InlineGlobals {
|
impl VisitMut for InlineGlobals {
|
||||||
noop_visit_mut_type!();
|
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) {
|
fn visit_mut_expr(&mut self, expr: &mut Expr) {
|
||||||
match expr {
|
match expr {
|
||||||
Expr::Ident(Ident { ref sym, span, .. }) => {
|
Expr::Ident(Ident { ref sym, span, .. }) => {
|
||||||
@ -336,4 +354,16 @@ mod tests {
|
|||||||
"const test = process.env['x']",
|
"const test = process.env['x']",
|
||||||
"const test = 'FOO'"
|
"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'"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user