feat(es/minifier): Handle boolean in Evaluator (#6756)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5953.
This commit is contained in:
HeYunfei 2023-01-06 16:15:07 +08:00 committed by GitHub
parent 48902b60d3
commit 8a6a1cbcf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -88,10 +88,13 @@ impl Evaluator {
match e {
Expr::Seq(s) => return self.eval(s.exprs.last()?),
Expr::Lit(l @ Lit::Null(..))
| Expr::Lit(l @ Lit::Num(..) | l @ Lit::Str(..) | l @ Lit::BigInt(..)) => {
return Some(EvalResult::Lit(l.clone()))
}
Expr::Lit(
l @ Lit::Num(..)
| l @ Lit::Str(..)
| l @ Lit::BigInt(..)
| l @ Lit::Bool(..)
| l @ Lit::Null(..),
) => return Some(EvalResult::Lit(l.clone())),
Expr::Tpl(t) => {
return self.eval_tpl(t);

View File

@ -66,6 +66,12 @@ fn simple() {
assert_eq!(eval("const foo = 4", "foo").unwrap(), "4");
}
#[test]
fn eval_lit() {
assert_eq!(eval("", "true").unwrap(), "true");
assert_eq!(eval("", "false").unwrap(), "false");
}
struct PartialInliner {
marks: Marks,
eval: Option<Evaluator>,