Skip to content

Commit 4a6e24b

Browse files
committed
improve: eval void 0 to undefined
1 parent 0b0a5c1 commit 4a6e24b

File tree

1 file changed

+5
-2
lines changed
  • turbopack/crates/turbopack-ecmascript/src/analyzer

1 file changed

+5
-2
lines changed

turbopack/crates/turbopack-ecmascript/src/analyzer/graph.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,12 @@ impl EvalContext {
420420

421421
Expr::Unary(UnaryExpr {
422422
op: op!("void"),
423-
arg: box Expr::Lit(Lit::Num(num)),
423+
// Only treat literals as constant undefined, allowing arbitrary values inside here
424+
// would mean that they can have sideeffects, and `JsValue::Constant` can't model
425+
// that.
426+
arg: box Expr::Lit(_),
424427
..
425-
}) if num.value == 0.0 => JsValue::Constant(ConstantValue::Undefined),
428+
}) => JsValue::Constant(ConstantValue::Undefined),
426429

427430
Expr::Unary(UnaryExpr {
428431
op: op!("!"), arg, ..

0 commit comments

Comments
 (0)