From: Timo Tijhof Date: Fri, 22 Dec 2017 17:47:21 +0000 (+0100) Subject: JavaScriptMinifier: Remove support for unused $statementsOnOwnLine flag X-Git-Tag: 1.31.0-rc.0~1114^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=93b8023946b0e;p=lhc%2Fweb%2Fwiklou.git JavaScriptMinifier: Remove support for unused $statementsOnOwnLine flag 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 --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index 67026f448e..6ef8573d50 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -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 diff --git a/includes/libs/JavaScriptMinifier.php b/includes/libs/JavaScriptMinifier.php index 141a5153d4..3be9ca160b 100644 --- a/includes/libs/JavaScriptMinifier.php +++ b/includes/libs/JavaScriptMinifier.php @@ -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; }