Index: trunk/phase3/includes/libs/JavaScriptDistiller.php |
— | — | @@ -28,33 +28,33 @@ |
29 | 29 | return $script; |
30 | 30 | } |
31 | 31 | |
32 | | - private static function stripHorizontalSpace( $script ) { |
| 32 | + public static function stripHorizontalSpace( $script ) { |
33 | 33 | $parser = self::createParser(); |
34 | 34 | // 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' ); |
36 | 36 | // Collapse horizontal whitespaces between unary operators into a single space |
37 | | - $parser->add( '/([+\\-])[ \\t]+([+\\-])/', '$2 $3' ); |
| 37 | + $parser->add( '/([+\-])[ \t]+([+\-])/', '$2 $3' ); |
38 | 38 | // Remove all remaining un-protected horizontal whitespace |
39 | | - $parser->add( '/[ \\t]+/'); |
| 39 | + $parser->add( '/[ \t]+/'); |
40 | 40 | // 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" ); |
42 | 42 | // Execute and return |
43 | 43 | return $parser->exec($script); |
44 | 44 | } |
45 | 45 | |
46 | | - private static function stripVerticalSpace( $script ) { |
| 46 | + public static function stripVerticalSpace( $script ) { |
47 | 47 | $parser = self::createParser(); |
48 | 48 | // Collapse whitespaces between and after a ){ pair (function definitions) |
49 | | - $parser->add( '/\\)\\s+\\{\\s+/', '){' ); |
| 49 | + $parser->add( '/\)\s+\{\s+/', '){' ); |
50 | 50 | // Collapse whitespaces between and after a ({ pair (JSON argument) |
51 | | - $parser->add( '/\\(\\s+\\{\\s+/', '({' ); |
| 51 | + $parser->add( '/\(\s+\{\s+/', '({' ); |
52 | 52 | // Collapse whitespaces between a parenthesis and a period (call chaining) |
53 | | - $parser->add( '/\\)\\s+\\./', ').'); |
| 53 | + $parser->add( '/\)\s+\./', ').'); |
54 | 54 | // Collapse vertical whitespaces which come directly after a semicolon or a comma |
55 | | - $parser->add( '/([;,])\\s+/', '$2' ); |
| 55 | + $parser->add( '/([;,])\s+/', '$2' ); |
56 | 56 | // 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' ); |
59 | 59 | return $parser->exec( $script ); |
60 | 60 | } |
61 | 61 | |
— | — | @@ -80,12 +80,12 @@ |
81 | 81 | $parser->add( '/\'([^\'\\\\]*(\\\\(.|[\r\n])[^\'\\\\]*)*)\'/', '$1' ); |
82 | 82 | $parser->add( '/"([^"\\\\]*(\\\\(.|[\r\n])[^"\\\\]*)*)"/', '$1' ); |
83 | 83 | // 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' ); |
86 | 86 | // Remove comments |
87 | | - $parser->add( '/\\/\\*(.|[\\r\\n])*?\\*\\//' ); |
| 87 | + $parser->add( '/\/\*(.|[\r\n])*?\*\//' ); |
88 | 88 | // 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' ); |
90 | 90 | return $parser; |
91 | 91 | } |
92 | 92 | } |
— | — | @@ -112,13 +112,13 @@ |
113 | 113 | const LENGTH = 2; |
114 | 114 | |
115 | 115 | // 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$/'; |
120 | 120 | private $ESCAPE = '/\\\./';//g |
121 | 121 | private $QUOTE = '/\'/'; |
122 | | - private $DELETED = '/\\x01[^\\x01]*\\x01/';//g |
| 122 | + private $DELETED = '/\x01[^\x01]*\x01/';//g |
123 | 123 | |
124 | 124 | public function add($expression, $replacement = '') { |
125 | 125 | // count the number of sub-expressions |