mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): do not constant fold 0 instanceof F (#8199)
This commit is contained in:
parent
bf266e13b0
commit
56b7f133fa
3 changed files with 14 additions and 14 deletions
|
|
@ -352,22 +352,17 @@ pub trait ConstantEvaluation<'a> {
|
||||||
if left.may_have_side_effects() {
|
if left.may_have_side_effects() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
if let Some(right_ident) = right.get_identifier_reference() {
|
||||||
let left_ty = ValueType::from(left);
|
let name = right_ident.name.as_str();
|
||||||
if left_ty == ValueType::Undetermined {
|
if matches!(name, "Object" | "Number" | "Boolean" | "String")
|
||||||
return None;
|
&& self.is_global_reference(right_ident)
|
||||||
}
|
{
|
||||||
if left_ty == ValueType::Object {
|
return Some(ConstantValue::Boolean(
|
||||||
if let Some(right_ident) = right.get_identifier_reference() {
|
name == "Object" && ValueType::from(left).is_object(),
|
||||||
if right_ident.name == "Object" && self.is_global_reference(right_ident) {
|
));
|
||||||
return Some(ConstantValue::Boolean(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
|
||||||
} else {
|
|
||||||
// Non-object types are never instances.
|
|
||||||
Some(ConstantValue::Boolean(false))
|
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ impl ValueType {
|
||||||
pub fn is_boolean(self) -> bool {
|
pub fn is_boolean(self) -> bool {
|
||||||
self == Self::Boolean
|
self == Self::Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_object(self) -> bool {
|
||||||
|
self == Self::Object
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `get_known_value_type`
|
/// `get_known_value_type`
|
||||||
|
|
|
||||||
|
|
@ -1609,6 +1609,7 @@ mod test {
|
||||||
|
|
||||||
// An unknown value should never be folded.
|
// An unknown value should never be folded.
|
||||||
test_same("x instanceof Foo");
|
test_same("x instanceof Foo");
|
||||||
|
test_same("0 instanceof Foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue