mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): a in b has error throwing side effect (#8406)
This commit is contained in:
parent
2f3a9dc74c
commit
7ce6a7c741
2 changed files with 4 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use oxc_ast::ast::*;
|
use oxc_ast::ast::*;
|
||||||
use oxc_syntax::operator::UnaryOperator;
|
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
|
||||||
|
|
||||||
/// A "simple" operator is one whose children are expressions, has no direct side-effects.
|
/// A "simple" operator is one whose children are expressions, has no direct side-effects.
|
||||||
fn is_simple_unary_operator(operator: UnaryOperator) -> bool {
|
fn is_simple_unary_operator(operator: UnaryOperator) -> bool {
|
||||||
|
|
@ -63,7 +63,6 @@ impl<'a> CheckForStateChange<'a, '_> for Expression<'a> {
|
||||||
if check_for_new_objects {
|
if check_for_new_objects {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
object_expr
|
object_expr
|
||||||
.properties
|
.properties
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -95,8 +94,8 @@ impl<'a> CheckForStateChange<'a, '_> for UnaryExpression<'a> {
|
||||||
|
|
||||||
impl<'a> CheckForStateChange<'a, '_> for BinaryExpression<'a> {
|
impl<'a> CheckForStateChange<'a, '_> for BinaryExpression<'a> {
|
||||||
fn check_for_state_change(&self, check_for_new_objects: bool) -> bool {
|
fn check_for_state_change(&self, check_for_new_objects: bool) -> bool {
|
||||||
// `instanceof` can throw `TypeError`
|
// `instanceof` and `in` can throw `TypeError`
|
||||||
if self.operator.is_instance_of() {
|
if matches!(self.operator, BinaryOperator::In | BinaryOperator::Instanceof) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let left = self.left.check_for_state_change(check_for_new_objects);
|
let left = self.left.check_for_state_change(check_for_new_objects);
|
||||||
|
|
|
||||||
|
|
@ -718,6 +718,7 @@ mod test {
|
||||||
fold_same("(0, o.f)();");
|
fold_same("(0, o.f)();");
|
||||||
fold("var obj = Object((null, 2, 3), 1, 2);", "var obj = Object(3, 1, 2);");
|
fold("var obj = Object((null, 2, 3), 1, 2);", "var obj = Object(3, 1, 2);");
|
||||||
fold_same("(0 instanceof 0, foo)");
|
fold_same("(0 instanceof 0, foo)");
|
||||||
|
fold_same("(0 in 0, foo)");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue