From 27508f06af55eb45b3d981112b75a6da6881eede Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 14 Mar 2011 18:04:39 +0000 Subject: [PATCH] Followup r83891: don't insert a newline before ++ or -- . Patch by Paul Copperman --- includes/libs/JavaScriptMinifier.php | 5 +++-- tests/phpunit/includes/libs/JavaScriptMinifierTest.php | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/libs/JavaScriptMinifier.php b/includes/libs/JavaScriptMinifier.php index 710ebe3389..d2a16f64bf 100644 --- a/includes/libs/JavaScriptMinifier.php +++ b/includes/libs/JavaScriptMinifier.php @@ -526,10 +526,11 @@ class JavaScriptMinifier { $state = self::STATEMENT; $lineLength = 0; } elseif( $maxLineLength > 0 && $lineLength + $end - $pos > $maxLineLength && - !isset( $semicolon[$state][$type] ) ) + !isset( $semicolon[$state][$type] ) && $type !== self::TYPE_INCR_OP ) { // This line would get too long if we added $token, so add a newline first. - // Only do this if it won't trigger semicolon insertion though. + // Only do this if it won't trigger semicolon insertion and if it won't + // put a postfix increment operator on its own line, which is illegal in js. $out .= "\n"; $lineLength = 0; // Check, whether we have to separate the token from the last one with whitespace diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php index 3f2209d394..fed7c10d78 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -71,6 +71,9 @@ class JavaScriptMinifierTest extends MediaWikiTestCase { // Division vs. regex nastiness array( "alert( (10+10) / '/'.charCodeAt( 0 ) + '//' );", "alert((10+10)/'/'.charCodeAt(0)+'//');" ), array( "if(1)/a /g.exec('Pa ss');", "if(1)/a /g.exec('Pa ss');" ), + + // newline insertion after 1000 chars: break after the "++", not before + array( str_repeat( ';', 996 ) . "if(x++);", str_repeat( ';', 996 ) . "if(x++\n);" ), ); } -- 2.20.1