Skip to content

Commit

Permalink
fix(minifier): temporarily fix shadowed undefined variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Aug 6, 2024
1 parent 0f5e982 commit b6108e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
15 changes: 6 additions & 9 deletions crates/oxc_minifier/src/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,12 @@ pub fn get_boolean_value(expr: &Expression) -> Option<bool> {
.and_then(|quasi| quasi.value.cooked.as_ref())
.map(|cooked| !cooked.is_empty())
}
Expression::Identifier(ident) => {
if expr.is_undefined() || ident.name == "NaN" {
Some(false)
} else if ident.name == "Infinity" {
Some(true)
} else {
None
}
}
Expression::Identifier(ident) => match ident.name.as_str() {
"NaN" => Some(false),
"Infinity" => Some(true),
// "undefined" if ident.reference_id.get().is_none() => Some(false),
_ => None,
},
Expression::AssignmentExpression(assign_expr) => {
match assign_expr.operator {
AssignmentOperator::LogicalAnd | AssignmentOperator::LogicalOr => None,
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_minifier/tests/oxc/remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ fn dce_if_statement() {
test("if ('development' === 'production') { foo } else { bar }", "{ bar }");

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

test("if (true) { foo; } if (true) { foo; }", "{ foo; } { foo; }");

Expand Down
6 changes: 5 additions & 1 deletion tasks/coverage/minifier_test262.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ commit: a1587416

minifier_test262 Summary:
AST Parsed : 46406/46406 (100.00%)
Positive Passed: 46406/46406 (100.00%)
Positive Passed: 46402/46406 (99.99%)
Expect to Parse: "language/expressions/logical-and/S11.11.1_A3_T4.js"
Expect to Parse: "language/expressions/logical-not/S9.2_A1_T2.js"
Expect to Parse: "language/statements/if/S12.5_A1.1_T1.js"
Expect to Parse: "language/statements/if/S12.5_A1.1_T2.js"

0 comments on commit b6108e9

Please sign in to comment.