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
19 changes: 15 additions & 4 deletions crates/oxc_ecmascript/src/constant_evaluation/value_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use oxc_ast::ast::{
AssignmentExpression, AssignmentOperator, BinaryExpression, ConditionalExpression, Expression,
LogicalExpression, LogicalOperator, StaticMemberExpression, UnaryExpression,
};
use oxc_ast::ast::*;
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};

use crate::{
Expand Down Expand Up @@ -111,6 +108,7 @@ impl<'a> DetermineValueType<'a> for Expression<'a> {
Expression::LogicalExpression(e) => e.value_type(is_global_reference),
Expression::ParenthesizedExpression(e) => e.expression.value_type(is_global_reference),
Expression::StaticMemberExpression(e) => e.value_type(is_global_reference),
Expression::NewExpression(e) => e.value_type(is_global_reference),
_ => ValueType::Undetermined,
}
}
Expand Down Expand Up @@ -288,3 +286,16 @@ impl<'a> DetermineValueType<'a> for StaticMemberExpression<'a> {
ValueType::Undetermined
}
}

impl<'a> DetermineValueType<'a> for NewExpression<'a> {
fn value_type(&self, is_global_reference: &impl IsGlobalReference<'a>) -> ValueType {
if let Some(ident) = self.callee.get_identifier_reference() {
if ident.name.as_str() == "Date"
&& is_global_reference.is_global_reference(ident) == Some(true)
{
return ValueType::Object;
}
}
ValueType::Undetermined
}
}
25 changes: 13 additions & 12 deletions crates/oxc_minifier/src/peephole/fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,19 +1209,20 @@ mod test {
}

#[test]
#[ignore]
fn test_object_comparison1() {
fold("!new Date()", "false");
fold("!!new Date()", "true");

fold("new Date() == null", "false");
fold("new Date() == undefined", "false");
fold("new Date() != null", "true");
fold("new Date() != undefined", "true");
fold("null == new Date()", "false");
fold("undefined == new Date()", "false");
fold("null != new Date()", "true");
fold("undefined != new Date()", "true");
fold("!new Date()", "!1");
fold("!!new Date()", "!0");
fold_same("!new Date(foo)");

fold("new Date() == null", "!1");
fold("new Date() == undefined", "!1");
fold("new Date() != null", "!0");
fold("new Date() != undefined", "!0");
fold("null == new Date()", "!1");
fold("undefined == new Date()", "!1");
fold("null != new Date()", "!0");
fold("undefined != new Date()", "!0");
fold("new Date(foo) != undefined", "new Date(foo) != null");
}

#[test]
Expand Down
Loading