From 2c3a46d0aa5ac7536d6d63a71cd901885bedfebf Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 7 Feb 2025 23:57:09 +0000 Subject: [PATCH] feat(ecmascript): support more simple expressions by `ValueType::from` (#8961) --- .../src/constant_evaluation/value_type.rs | 10 +++++++++- crates/oxc_minifier/tests/ecmascript/value_type.rs | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs b/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs index 9ff470aa55e21..bba92892383b0 100644 --- a/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs +++ b/crates/oxc_ecmascript/src/constant_evaluation/value_type.rs @@ -71,7 +71,15 @@ impl<'a> From<&Expression<'a>> for ValueType { Expression::ObjectExpression(_) | Expression::ArrayExpression(_) | Expression::RegExpLiteral(_) - | Expression::FunctionExpression(_) => Self::Object, + | Expression::FunctionExpression(_) + | Expression::ArrowFunctionExpression(_) + | Expression::ClassExpression(_) => Self::Object, + Expression::MetaProperty(meta_prop) => { + match (meta_prop.meta.name.as_str(), meta_prop.property.name.as_str()) { + ("import", "meta") => Self::Object, + _ => Self::Undetermined, + } + } Expression::Identifier(ident) => match ident.name.as_str() { "undefined" => Self::Undefined, "NaN" | "Infinity" => Self::Number, diff --git a/crates/oxc_minifier/tests/ecmascript/value_type.rs b/crates/oxc_minifier/tests/ecmascript/value_type.rs index 25c9716ca56da..cf0ddb880ae0f 100644 --- a/crates/oxc_minifier/tests/ecmascript/value_type.rs +++ b/crates/oxc_minifier/tests/ecmascript/value_type.rs @@ -30,8 +30,10 @@ fn literal_tests() { test("[0]", ValueType::Object); test("/a/", ValueType::Object); test("(function () {})", ValueType::Object); - // test("(() => {})", ValueType::Object); - // test("(class {})", ValueType::Object); + test("(() => {})", ValueType::Object); + test("(class {})", ValueType::Object); + test("import.meta", ValueType::Object); + // NOTE: new.target is undefined or object } #[test]