Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/oxc_minifier/src/compressor/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ pub fn get_boolean_value(expr: &Expression) -> Option<bool> {
.map(|cooked| !cooked.is_empty())
}
Expression::Identifier(ident) => {
if expr.is_undefined() || ident.name == "NaN" {
/* `undefined` can be a shadowed variable expr.is_undefined() || */
if ident.name == "NaN" {
Some(false)
} else if ident.name == "Infinity" {
Some(true)
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_minifier/tests/oxc/remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ fn remove_dead_code() {

test("!!false ? foo : bar;", "bar");
test("!!true ? foo : bar;", "foo");

// Shadowed `undefined` as a variable should not be erased.
test(
"function foo(undefined) { if (!undefined) { } }",
"function foo(undefined){if(!undefined){}}",
);
}