fix(es/minifier): Don't drop typeof (#4883)

This commit is contained in:
Donny/강동윤 2022-06-05 16:43:53 +09:00 committed by GitHub
parent 098115573d
commit 06420d99bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 7 deletions

View 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"
}
}

View File

@ -0,0 +1,2 @@
if (typeof process === "undefined") {
}

View File

@ -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,
..
}) => {

View File

@ -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 })),
},