Skip to content
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
13 changes: 9 additions & 4 deletions crates/oxc_ecmascript/src/constant_evaluation/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,20 @@ impl<'a> From<&BinaryExpression<'a>> for ValueType {
fn from(e: &BinaryExpression<'a>) -> Self {
match e.operator {
BinaryOperator::Addition => {
let left_ty = Self::from(&e.left);
let right_ty = Self::from(&e.right);
if left_ty == Self::String || right_ty == Self::String {
let left = Self::from(&e.left);
let right = Self::from(&e.right);
if left == Self::Boolean
&& matches!(right, Self::Undefined | Self::Null | Self::Number)
{
return Self::Number;
}
if left == Self::String || right == Self::String {
return Self::String;
}
// There are some pretty weird cases for object types:
// {} + [] === "0"
// [] + {} === "[object Object]"
if left_ty == Self::Object || right_ty == Self::Object {
if left == Self::Object || right == Self::Object {
return Self::Undetermined;
}
Self::Undetermined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,7 @@ mod test {

test("(x = 1) === 1", "(x = 1) == 1");
test("(x = 1) !== 1", "(x = 1) != 1");
test("!0 + null !== 1", "!0 + null != 1");
}

#[test]
Expand Down
Loading