Skip to content

Commit aa0154d

Browse files
authoredMar 12, 2024··
fix(es/minifier): Fix evaluation of array literals with void 0 (#8733)
**Related issue:** - Closes #8706
1 parent d9c49d8 commit aa0154d

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"defaults": true
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log([void 0] + 'swc');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("swc");

‎crates/swc_ecma_utils/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,16 @@ pub trait ExprExt {
10271027
let ExprOrSpread { ref expr, .. } = *elem;
10281028
match &**expr {
10291029
Expr::Lit(Lit::Null(..)) => Cow::Borrowed(""),
1030+
Expr::Unary(UnaryExpr {
1031+
op: op!("void"),
1032+
arg,
1033+
..
1034+
}) => {
1035+
if arg.may_have_side_effects(ctx) {
1036+
return Value::Unknown;
1037+
}
1038+
Cow::Borrowed("")
1039+
}
10301040
Expr::Ident(Ident { sym: undefined, .. })
10311041
if &**undefined == "undefined" =>
10321042
{

0 commit comments

Comments
 (0)
Please sign in to comment.