Followup r83891: don't insert a newline before ++ or -- . Patch by Paul Copperman
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 14 Mar 2011 18:04:39 +0000 (18:04 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 14 Mar 2011 18:04:39 +0000 (18:04 +0000)
includes/libs/JavaScriptMinifier.php
tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index 710ebe3..d2a16f6 100644 (file)
@@ -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
index 3f2209d..fed7c10 100644 (file)
@@ -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);" ),
                );
        }