Rich-Harris / butternut

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

Bug: Invalid semi-colon in edge cases #115

Closed loilo closed 7 years ago

loilo commented 7 years ago

I couldn't even find a proper descriptive title for this.

So, trying to squash minified AdapterJS revealed another problem.

Boiled down to the essence, the following code generates invalid JavaScript:

function fn () {
  if ( any_condition )
    global_variable = true;
  else
    var local_variable = true;
}

The invalid output is the following:

function fn(){any_condition&&(global_variable=!0;)}
                           // invalid semicolon ^

This will only happen (list may not be exhaustive) if: