Strip empty else-statements

Fixes #91
This commit is contained in:
Matthias Mullie 2016-01-04 14:59:16 -08:00
parent 1e59ad8119
commit 31371a6a67
2 changed files with 16 additions and 0 deletions

View File

@ -307,6 +307,16 @@ class JS extends Minify
*/
$content = preg_replace('/(for\([^;]*;[^;]*;[^;\{]*\));(\}|$)/s', '\\1;;\\2', $content);
/*
* We also can't strip empty else-statements. Even though they're
* useless and probably shouldn't be in the code in the first place, we
* shouldn't be stripping the `;` that follows it as it breaks the code.
* We can just remove those useless else-statements completely.
*
* @see https://github.com/matthiasmullie/minify/issues/91
*/
$content = preg_replace('/else;/s', '', $content);
/*
* We also don't really want to terminate statements followed by closing
* curly braces (which we've ignored completely up until now) or end-of-

View File

@ -659,6 +659,12 @@ BUG
"for(;;ja||(ja=!0)){}",
);
// https://github.com/matthiasmullie/minify/issues/91
$tests[] = array(
'if(true){if(true)console.log("test")else;}',
'if(!0){if(!0)console.log("test")}',
);
return $tests;
}
}