r82380 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82379‎ | r82380 | r82381 >
Date:06:54, 18 February 2011
Author:tstarling
Status:ok
Tags:
Comment:
Made the regexes slightly more readable by undoubling the backslashes where possible. Tested by ensuring that the minifier output is the same before and after, with jquery.js as input.
Modified paths:
  • /trunk/phase3/includes/libs/JavaScriptDistiller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/libs/JavaScriptDistiller.php
@@ -28,33 +28,33 @@
2929 return $script;
3030 }
3131
32 - private static function stripHorizontalSpace( $script ) {
 32+ public static function stripHorizontalSpace( $script ) {
3333 $parser = self::createParser();
3434 // Collapse horizontal whitespaces between variable names into a single space
35 - $parser->add( '/(\\b|\\$)[ \\t]+(\\b|\\$)/', '$2 $3' );
 35+ $parser->add( '/(\b|\$)[ \t]+(\b|\$)/', '$2 $3' );
3636 // Collapse horizontal whitespaces between unary operators into a single space
37 - $parser->add( '/([+\\-])[ \\t]+([+\\-])/', '$2 $3' );
 37+ $parser->add( '/([+\-])[ \t]+([+\-])/', '$2 $3' );
3838 // Remove all remaining un-protected horizontal whitespace
39 - $parser->add( '/[ \\t]+/');
 39+ $parser->add( '/[ \t]+/');
4040 // Collapse multiple vertical whitespaces with some horizontal spaces between them
41 - $parser->add( '/[\\r\\n]+[ \\t]*[\\r\\n]+/', "\n" );
 41+ $parser->add( '/[\r\n]+[ \t]*[\r\n]+/', "\n" );
4242 // Execute and return
4343 return $parser->exec($script);
4444 }
4545
46 - private static function stripVerticalSpace( $script ) {
 46+ public static function stripVerticalSpace( $script ) {
4747 $parser = self::createParser();
4848 // Collapse whitespaces between and after a ){ pair (function definitions)
49 - $parser->add( '/\\)\\s+\\{\\s+/', '){' );
 49+ $parser->add( '/\)\s+\{\s+/', '){' );
5050 // Collapse whitespaces between and after a ({ pair (JSON argument)
51 - $parser->add( '/\\(\\s+\\{\\s+/', '({' );
 51+ $parser->add( '/\(\s+\{\s+/', '({' );
5252 // Collapse whitespaces between a parenthesis and a period (call chaining)
53 - $parser->add( '/\\)\\s+\\./', ').');
 53+ $parser->add( '/\)\s+\./', ').');
5454 // Collapse vertical whitespaces which come directly after a semicolon or a comma
55 - $parser->add( '/([;,])\\s+/', '$2' );
 55+ $parser->add( '/([;,])\s+/', '$2' );
5656 // Collapse whitespaces between multiple parenthesis/brackets of similar direction
57 - $parser->add( '/([\\)\\}])\\s+([\\)\\}])/', '$2$3' );
58 - $parser->add( '/([\\(\\{])\\s+([\\(\\{])/', '$2$3' );
 57+ $parser->add( '/([\)\}])\s+([\)\}])/', '$2$3' );
 58+ $parser->add( '/([\(\{])\\s+([\(\{])/', '$2$3' );
5959 return $parser->exec( $script );
6060 }
6161
@@ -80,12 +80,12 @@
8181 $parser->add( '/\'([^\'\\\\]*(\\\\(.|[\r\n])[^\'\\\\]*)*)\'/', '$1' );
8282 $parser->add( '/"([^"\\\\]*(\\\\(.|[\r\n])[^"\\\\]*)*)"/', '$1' );
8383 // Protect regular expressions
84 - $parser->add( '/[ \\t]+((\\/[^\\r\\n\\*][^\\/\\r\\n\\\\]*(\\\\.[^\\/\\r\\n\\\\]*)*\\/(i|g)*))/', '$1' );
85 - $parser->add( '/([^\\w\\$\\/\'"*)\\?:](\\/[^\\r\\n\\*][^\\/\\r\\n\\\\]*(\\\\.[^\\/\\r\\n\\\\]*)*\\/(i|g)*))/', '$1' );
 84+ $parser->add( '/[ \t]+((\/[^\r\n\*][^\/\r\n\\\\]*(\\\\.[^\/\r\n\\\\]*)*\/(i|g)*))/', '$1' );
 85+ $parser->add( '/([^\w\$\/\'"*)\?:](\/[^\r\n\*][^\/\r\n\\\\]*(\\\\.[^\/\r\n\\\\]*)*\/(i|g)*))/', '$1' );
8686 // Remove comments
87 - $parser->add( '/\\/\\*(.|[\\r\\n])*?\\*\\//' );
 87+ $parser->add( '/\/\*(.|[\r\n])*?\*\//' );
8888 // Preserve the newline after a C++-style comment -- bug 27046
89 - $parser->add( '/\\/\\/[^\\r\\n]*([\\r\\n])/', '$2' );
 89+ $parser->add( '/\/\/[^\r\n]*([\r\n])/', '$2' );
9090 return $parser;
9191 }
9292 }
@@ -112,13 +112,13 @@
113113 const LENGTH = 2;
114114
115115 // used to determine nesting levels
116 - private $GROUPS = '/\\(/';//g
117 - private $SUB_REPLACE = '/\\$\\d/';
118 - private $INDEXED = '/^\\$\\d+$/';
119 - private $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/';
 116+ private $GROUPS = '/\(/';//g
 117+ private $SUB_REPLACE = '/\$\d/';
 118+ private $INDEXED = '/^\$\d+$/';
 119+ private $TRIM = '/([\'"])\1\.(.*)\.\1\1$/';
120120 private $ESCAPE = '/\\\./';//g
121121 private $QUOTE = '/\'/';
122 - private $DELETED = '/\\x01[^\\x01]*\\x01/';//g
 122+ private $DELETED = '/\x01[^\x01]*\x01/';//g
123123
124124 public function add($expression, $replacement = '') {
125125 // count the number of sub-expressions

Follow-up revisions

RevisionCommit summaryAuthorDate
r824021.17wmf1: MFT r82380, r82384, r82399catrope14:28, 18 February 2011

Status & tagging log