diff --git a/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs b/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs index 085ccd50c57d8..99604821bbc8a 100644 --- a/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs +++ b/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs @@ -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::{ @@ -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, } } @@ -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 + } +} diff --git a/crates/oxc_minifier/src/peephole/fold_constants.rs b/crates/oxc_minifier/src/peephole/fold_constants.rs index ae7d969c4a6e0..c74937d231796 100644 --- a/crates/oxc_minifier/src/peephole/fold_constants.rs +++ b/crates/oxc_minifier/src/peephole/fold_constants.rs @@ -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]