feat(minifier): fold typeof (() => {}) to 'function' (#8948)

This commit is contained in:
sapphi-red committed 2025-02-08 01:18:10 +09:00
1 parent 36007de5d1
commit 9ffe9e9501
2 files changed
+4 -1

No files matched your search

@@ -401,7 +401,9 @@ pub trait ConstantEvaluation<'a>: MayHaveSideEffects {
}
"object"
}
Expression::FunctionExpression(_) => "function",
Expression::FunctionExpression(_) | Expression::ArrowFunctionExpression(_) => {
"function"
}
Expression::StringLiteral(_) => "string",
Expression::NumericLiteral(_) => "number",
Expression::BooleanLiteral(_) => "boolean",
@@ -1160,6 +1160,7 @@ mod test {
fold("x = typeof {}", "x = \"object\"");
test("var foo; NOOP(x = typeof { foo })", "var foo; NOOP(x = \"object\")");
fold("x = typeof function() {}", "x = 'function'");
fold("x = typeof (() => {})", "x = 'function'");
fold_same("x = typeof foo"); // no sideeffect, but we don't know the result
fold_same("x = typeof[1,[foo()]]");