JavaScriptMinifier: Remove support for unused $statementsOnOwnLine flag
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 22 Dec 2017 17:47:21 +0000 (18:47 +0100)
committerKrinkle <krinklemail@gmail.com>
Fri, 22 Dec 2017 18:38:04 +0000 (18:38 +0000)
The $wgResourceLoaderMinifierStatementsOnOwnLine config var was deprecated
in MediaWiki 1.27. The parameter of minify() was not used by other code, and
no new usage has been introduced since then, either.

Remove the feature from JavaScriptMinifier, and add a release note for that.
The same 1.31 release notes also contain a note already about the removal
of the configuration variable.

The feature was not covered by unit tests.

The following private variables have been removed, that are no longer used
due to this change: $newlineBefore, $newlineAfter, $newlineAdded.

Change-Id: I2cbf271156c1954abb982531d0125b4b9573b12c

RELEASE-NOTES-1.31
includes/libs/JavaScriptMinifier.php

index 67026f4..6ef8573 100644 (file)
@@ -149,6 +149,9 @@ changes to languages because of Phabricator reports.
   * WatchedItem::IGNORE_USER_RIGHTS
   * WatchedItem::CHECK_USER_RIGHTS
   * WatchedItem::DEPRECATED_USAGE_TIMESTAMP
+* The $statementsOnOwnLine parameter of JavaScriptMinifier::minify was removed.
+  The corresponding configuration variable ($wgResourceLoaderMinifierStatementsOnOwnLine)
+  has been deprecated since 1.27 and was removed as well.
 
 == Compatibility ==
 MediaWiki 1.31 requires PHP 5.5.9 or later. There is experimental support for
index 141a515..3be9ca1 100644 (file)
@@ -74,11 +74,10 @@ class JavaScriptMinifier {
         *       or when required to guard against semicolon insertion.
         *
         * @param string $s JavaScript code to minify
-        * @param bool $statementsOnOwnLine Whether to put each statement on its own line
         * @param int $maxLineLength Maximum length of a single line, or -1 for no maximum.
         * @return String Minified code
         */
-       public static function minify( $s, $statementsOnOwnLine = false, $maxLineLength = 1000 ) {
+       public static function minify( $s, $maxLineLength = 1000 ) {
                // First we declare a few tables that contain our parsing rules
 
                // $opChars : characters, which can be combined without whitespace in between them
@@ -387,23 +386,6 @@ class JavaScriptMinifier {
                        )
                );
 
-               // Rules for when newlines should be inserted if
-               // $statementsOnOwnLine is enabled.
-               // $newlineBefore is checked before switching state,
-               // $newlineAfter is checked after
-               $newlineBefore = array(
-                       self::STATEMENT => array(
-                               self::TYPE_BRACE_CLOSE => true,
-                       ),
-               );
-               $newlineAfter = array(
-                       self::STATEMENT => array(
-                               self::TYPE_BRACE_OPEN => true,
-                               self::TYPE_PAREN_CLOSE => true,
-                               self::TYPE_SEMICOLON => true,
-                       ),
-               );
-
                // $divStates : Contains all states that can be followed by a division operator
                $divStates = array(
                        self::EXPRESSION_OP          => true,
@@ -580,15 +562,6 @@ class JavaScriptMinifier {
                        $pos = $end;
                        $newlineFound = false;
 
-                       // Output a newline after the token if required
-                       // This is checked before AND after switching state
-                       $newlineAdded = false;
-                       if ( $statementsOnOwnLine && !$newlineAdded && isset( $newlineBefore[$state][$type] ) ) {
-                               $out .= "\n";
-                               $lineLength = 0;
-                               $newlineAdded = true;
-                       }
-
                        // Now that we have output our token, transition into the new state.
                        if( isset( $push[$state][$type] ) && count( $stack ) < self::STACK_LIMIT ) {
                                $stack[] = $push[$state][$type];
@@ -598,12 +571,6 @@ class JavaScriptMinifier {
                        } elseif( isset( $goto[$state][$type] ) ) {
                                $state = $goto[$state][$type];
                        }
-
-                       // Check for newline insertion again
-                       if ( $statementsOnOwnLine && !$newlineAdded && isset( $newlineAfter[$state][$type] ) ) {
-                               $out .= "\n";
-                               $lineLength = 0;
-                       }
                }
                return $out;
        }