Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

Bug: Auto-inserted semicolons conflict with negated if/else blocks #109

Closed loilo closed 7 years ago

loilo commented 7 years ago

So as promised, I tested Butternut with more minified libraries. Current victim is the honorable 6to5 library.

Butternut fails on it, and this time (after actually installing butternut on my PC) I was clever enough to hunt down the cause.

In essence, this fails:

function fn_1 () {
  if ( !any_condition ) {
    fn_2()
  } else {
    fn_3()
  }return true
}

This fails because Buttercup does not combine two of its behaviours correctly:

The issue is that it gets the order of those operations wrong, first adding the semicolon and swapping ternary operator statements after that, producing the following invalid code:

function fn_1(){any_condition?fn_3();:fn_2()return !0}
Rich-Harris commented 7 years ago

Thanks for these repros, they are extremely helpful!

loilo commented 7 years ago

My pleasure. 🤗