Skip to content

Commit

Permalink
feat(es/minifier): Handle boolean in Evaluator (#6756)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #5953.
  • Loading branch information
hyf0 committed Jan 6, 2023
1 parent 48902b6 commit 8a6a1cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/swc_ecma_minifier/src/eval.rs
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_ecma_minifier/tests/eval.rs
Expand Up @@ -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>,
Expand Down

0 comments on commit 8a6a1cb

Please sign in to comment.