feat(ecmascript): support more simple expressions by ValueType::from (#8961)

This commit is contained in:
sapphi-red committed 2025-02-07 23:57:09 +00:00
1 parent e1fd3e82d4
commit 2c3a46d0aa
2 files changed
+13 -3

No files matched your search

@@ -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,
@@ -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]