Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(minifier): instanceof has error throwing side effect #8378

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/oxc_ecmascript/src/side_effects/check_for_state_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_syntax/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading