Rich-Harris / butternut

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

Only remove from || onwards if left side of logical-or is truthy #56

Closed jbt closed 7 years ago

jbt commented 7 years ago

This fixes #54 - previously code was being removed from the beginning of the left expression, whereas the whole lefthand expression should be kept.

Happy to put in test(s) too, just wasn't entirely sure which file to put it/them in. As it turns out it was also failing for any logical-or expression where the lefthand side was known-truthy (e.g. x = 1 || 0; 1 was producing x=,1)

jbt commented 7 years ago

I added some test cases around logical expressions in a new logical-expressions.js. Lots of different cases so apologies if it's overkill.

My best guess why this wasn't failing before was because the true || false test case was creating an intermediate emptystring, but subsequently the Literal minification of true to !0 was reinstating the lefthand expression again.

Rich-Harris commented 7 years ago

This is extremely helpful, thank you very much!