mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): fix panic in peephole_minimize_conditions (#8242)
https://github.com/oxc-project/monitor-oxc caught some crashes. Make things safer by returning falling back to true.
This commit is contained in:
parent
ad9a0a9c4a
commit
d2f8eaa842
1 changed files with 7 additions and 10 deletions
|
|
@ -355,8 +355,6 @@ impl<'a> PeepholeMinimizeConditions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let in_boolean_context = Self::is_in_boolean_context(ctx);
|
|
||||||
|
|
||||||
// `a ? false : true` -> `!a`
|
// `a ? false : true` -> `!a`
|
||||||
// `a ? true : false` -> `!!a`
|
// `a ? true : false` -> `!!a`
|
||||||
if let (
|
if let (
|
||||||
|
|
@ -377,7 +375,7 @@ impl<'a> PeepholeMinimizeConditions {
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
let ident = ctx.ast.move_expression(&mut expr.test);
|
let ident = ctx.ast.move_expression(&mut expr.test);
|
||||||
|
|
||||||
if in_boolean_context {
|
if Self::is_in_boolean_context(ctx) {
|
||||||
return Some(ident);
|
return Some(ident);
|
||||||
}
|
}
|
||||||
return Some(ctx.ast.expression_unary(
|
return Some(ctx.ast.expression_unary(
|
||||||
|
|
@ -399,7 +397,7 @@ impl<'a> PeepholeMinimizeConditions {
|
||||||
let ident = ctx.ast.move_expression(&mut expr.test);
|
let ident = ctx.ast.move_expression(&mut expr.test);
|
||||||
return Some(ctx.ast.expression_logical(
|
return Some(ctx.ast.expression_logical(
|
||||||
expr.span,
|
expr.span,
|
||||||
if in_boolean_context {
|
if Self::is_in_boolean_context(ctx) {
|
||||||
ident
|
ident
|
||||||
} else {
|
} else {
|
||||||
ctx.ast.expression_unary(
|
ctx.ast.expression_unary(
|
||||||
|
|
@ -438,7 +436,7 @@ impl<'a> PeepholeMinimizeConditions {
|
||||||
let ident = ctx.ast.move_expression(&mut expr.test);
|
let ident = ctx.ast.move_expression(&mut expr.test);
|
||||||
return Some(ctx.ast.expression_logical(
|
return Some(ctx.ast.expression_logical(
|
||||||
expr.span,
|
expr.span,
|
||||||
if in_boolean_context {
|
if Self::is_in_boolean_context(ctx) {
|
||||||
ident
|
ident
|
||||||
} else {
|
} else {
|
||||||
ctx.ast.expression_unary(
|
ctx.ast.expression_unary(
|
||||||
|
|
@ -467,7 +465,9 @@ impl<'a> PeepholeMinimizeConditions {
|
||||||
| Ancestor::WhileStatementTest(_)
|
| Ancestor::WhileStatementTest(_)
|
||||||
| Ancestor::ForStatementTest(_)
|
| Ancestor::ForStatementTest(_)
|
||||||
| Ancestor::DoWhileStatementTest(_)
|
| Ancestor::DoWhileStatementTest(_)
|
||||||
| Ancestor::ExpressionStatementExpression(_) => return true,
|
| Ancestor::ExpressionStatementExpression(_)
|
||||||
|
| Ancestor::SequenceExpressionExpressions(_)
|
||||||
|
| Ancestor::ProgramBody(_) => return true,
|
||||||
Ancestor::CallExpressionArguments(_)
|
Ancestor::CallExpressionArguments(_)
|
||||||
| Ancestor::AssignmentPatternRight(_)
|
| Ancestor::AssignmentPatternRight(_)
|
||||||
| Ancestor::BindingRestElementArgument(_)
|
| Ancestor::BindingRestElementArgument(_)
|
||||||
|
|
@ -482,10 +482,7 @@ impl<'a> PeepholeMinimizeConditions {
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(debug_assertions)]
|
true
|
||||||
unreachable!();
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_minimize_binary(
|
fn try_minimize_binary(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue