mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(minifier): instanceof has error throwing side effect (#8378)
This commit is contained in:
parent
c1c0d71162
commit
c0a3ddac28
3 changed files with 14 additions and 3 deletions
|
|
@ -95,10 +95,15 @@ impl<'a> CheckForStateChange<'a, '_> for UnaryExpression<'a> {
|
|||
|
||||
impl<'a> CheckForStateChange<'a, '_> for BinaryExpression<'a> {
|
||||
fn check_for_state_change(&self, check_for_new_objects: bool) -> bool {
|
||||
// `instanceof` can throw `TypeError`
|
||||
if self.operator.is_instance_of() {
|
||||
return true;
|
||||
}
|
||||
let left = self.left.check_for_state_change(check_for_new_objects);
|
||||
let right = self.right.check_for_state_change(check_for_new_objects);
|
||||
|
||||
left || right
|
||||
if left {
|
||||
return true;
|
||||
}
|
||||
self.right.check_for_state_change(check_for_new_objects)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -717,6 +717,7 @@ mod test {
|
|||
fold("(function k() {}, k(), baz())", "k(), baz()");
|
||||
fold_same("(0, o.f)();");
|
||||
fold("var obj = Object((null, 2, 3), 1, 2);", "var obj = Object(3, 1, 2);");
|
||||
fold_same("(0 instanceof 0, foo)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -268,6 +268,11 @@ impl BinaryOperator {
|
|||
self == Self::In
|
||||
}
|
||||
|
||||
/// Returns `true` if this is an [`In`](BinaryOperator::Instanceof) operator.
|
||||
pub fn is_instance_of(self) -> bool {
|
||||
self == Self::Instanceof
|
||||
}
|
||||
|
||||
/// Returns `true` for any bitwise operator
|
||||
#[rustfmt::skip]
|
||||
pub fn is_bitwise(self) -> bool {
|
||||
|
|
|
|||
Loading…
Reference in a new issue