Skip to content

Commit

Permalink
fix(es/minifier): Fix evaluation of array literals with void 0 (#8733)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8706
  • Loading branch information
kdy1 authored Mar 12, 2024
1 parent d9c49d8 commit aa0154d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"defaults": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log([void 0] + 'swc');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("swc");
10 changes: 10 additions & 0 deletions crates/swc_ecma_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,16 @@ pub trait ExprExt {
let ExprOrSpread { ref expr, .. } = *elem;
match &**expr {
Expr::Lit(Lit::Null(..)) => Cow::Borrowed(""),
Expr::Unary(UnaryExpr {
op: op!("void"),
arg,
..
}) => {
if arg.may_have_side_effects(ctx) {
return Value::Unknown;
}
Cow::Borrowed("")
}
Expr::Ident(Ident { sym: undefined, .. })
if &**undefined == "undefined" =>
{
Expand Down

0 comments on commit aa0154d

Please sign in to comment.