Skip to content

Commit b345800

Browse files
committed
Fix issue #394
1 parent acaee1b commit b345800

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/JS.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ protected function stripWhitespace($content)
429429
$content = preg_replace('/(for\([^;\{]*;[^;\{]*;[^;\{]*(\{([^\{\}]*(?-2))*[^\{\}]*\})?[^;\{]*\));(\}|$)/s', '\\1;;\\4', $content);
430430

431431
$content = preg_replace('/(for\([^;\{]+\s+in\s+[^;\{]+\));(\}|$)/s', '\\1;;\\2', $content);
432+
433+
/*
434+
* Do the same for the if's that don't have a body but are followed by ;}
435+
*/
436+
$content = preg_replace('/(\bif\s*\([^{;]*\));\}/s', '\\1;;}', $content);
437+
432438
/*
433439
* Below will also keep `;` after a `do{}while();` along with `while();`
434440
* While these could be stripped after do-while, detecting this

tests/js/JSTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,16 @@ function someOtherFunction() {
13211321
'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'
13221322
);
13231323

1324+
// https://github.com/matthiasmullie/minify/issues/394
1325+
$tests[] = array(
1326+
'var a = function(){var b; if(b=3);}',
1327+
'var a=function(){var b;if(b=3);}',
1328+
);
1329+
$tests[] = array(
1330+
'jQuery(document).ready(function(e){ if (jQuery(document.body).on("updated_wc_div", o), jQuery(document.body).on("updated_cart_totals", o)); });',
1331+
'jQuery(document).ready(function(e){if(jQuery(document.body).on("updated_wc_div",o),jQuery(document.body).on("updated_cart_totals",o));})',
1332+
);
1333+
13241334
// known minified files to help doublecheck changes in places not yet
13251335
// anticipated in these tests
13261336
$files = glob(__DIR__.'/sample/minified/*.js');

0 commit comments

Comments
 (0)