mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(minifier): temporarily fix shadowed undefined variable (#4678)
This commit is contained in:
parent
0f5e982d19
commit
9be29af9d4
3 changed files with 16 additions and 14 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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; }");
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue