mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 20:28:43 +03:00
fix(es/minifier): Don't drop typeof
(#4883)
This commit is contained in:
parent
098115573d
commit
06420d99bb
18
crates/swc/tests/fixture/issues-4xxx/4855/input/1/.swcrc
Normal file
18
crates/swc/tests/fixture/issues-4xxx/4855/input/1/.swcrc
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"jsc": {
|
||||
"externalHelpers": true,
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": false
|
||||
},
|
||||
"target": "es2022",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": true,
|
||||
"mangle": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
if (typeof process === "undefined") {
|
||||
}
|
@ -535,7 +535,7 @@ impl Pure<'_> {
|
||||
if self.options.side_effects {
|
||||
match e {
|
||||
Expr::Unary(UnaryExpr {
|
||||
op: op!("void") | op!("typeof") | op!(unary, "+") | op!(unary, "-"),
|
||||
op: op!("void") | op!(unary, "+") | op!(unary, "-"),
|
||||
arg,
|
||||
..
|
||||
}) => {
|
||||
|
@ -1516,12 +1516,9 @@ fn ignore_result(e: Expr, drop_str_lit: bool, ctx: &ExprCtx) -> Option<Expr> {
|
||||
Some(Expr::Unary(UnaryExpr { span, op, arg }))
|
||||
}
|
||||
|
||||
op!("void")
|
||||
| op!("typeof")
|
||||
| op!(unary, "+")
|
||||
| op!(unary, "-")
|
||||
| op!("!")
|
||||
| op!("~") => ignore_result(*arg, true, ctx),
|
||||
op!("void") | op!(unary, "+") | op!(unary, "-") | op!("!") | op!("~") => {
|
||||
ignore_result(*arg, true, ctx)
|
||||
}
|
||||
_ => Some(Expr::Unary(UnaryExpr { span, op, arg })),
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user