This commit is contained in:
Simon 2022-04-16 12:12:59 +03:00
parent acaee1b7ca
commit b3458006ef
2 changed files with 16 additions and 0 deletions

View File

@ -429,6 +429,12 @@ class JS extends Minify
$content = preg_replace('/(for\([^;\{]*;[^;\{]*;[^;\{]*(\{([^\{\}]*(?-2))*[^\{\}]*\})?[^;\{]*\));(\}|$)/s', '\\1;;\\4', $content);
$content = preg_replace('/(for\([^;\{]+\s+in\s+[^;\{]+\));(\}|$)/s', '\\1;;\\2', $content);
/*
* Do the same for the if's that don't have a body but are followed by ;}
*/
$content = preg_replace('/(\bif\s*\([^{;]*\));\}/s', '\\1;;}', $content);
/*
* Below will also keep `;` after a `do{}while();` along with `while();`
* While these could be stripped after do-while, detecting this

View File

@ -1321,6 +1321,16 @@ var largeScreen=2048',
'if(l!==3){for(var V=w.length;l<V;V+=w.map(function(e){if(e>5){return e-5}return e}).length);}else var C=3'
);
// https://github.com/matthiasmullie/minify/issues/394
$tests[] = array(
'var a = function(){var b; if(b=3);}',
'var a=function(){var b;if(b=3);}',
);
$tests[] = array(
'jQuery(document).ready(function(e){ if (jQuery(document.body).on("updated_wc_div", o), jQuery(document.body).on("updated_cart_totals", o)); });',
'jQuery(document).ready(function(e){if(jQuery(document.body).on("updated_wc_div",o),jQuery(document.body).on("updated_cart_totals",o));})',
);
// known minified files to help doublecheck changes in places not yet
// anticipated in these tests
$files = glob(__DIR__.'/sample/minified/*.js');