Index: branches/5.2.x/core/units/helpers/minifiers/js_minify_helper.php =================================================================== diff -u -N -r13840 -r14095 --- branches/5.2.x/core/units/helpers/minifiers/js_minify_helper.php (.../js_minify_helper.php) (revision 13840) +++ branches/5.2.x/core/units/helpers/minifiers/js_minify_helper.php (.../js_minify_helper.php) (revision 14095) @@ -51,59 +51,53 @@ defined('FULL_PATH') or die('restricted access!'); -define('JSM_ORD_LF', 10); -define('JSM_ORD_SPACE', 32); -define('JSM_ACTION_KEEP_A', 1); -define('JSM_ACTION_DELETE_A', 2); -define('JSM_ACTION_DELETE_A_B', 3); - class JsMinifyHelper extends kHelper { - /*const ORD_LF = 10; + const ORD_LF = 10; const ORD_SPACE = 32; const ACTION_KEEP_A = 1; const ACTION_DELETE_A = 2; - const ACTION_DELETE_A_B = 3;*/ + const ACTION_DELETE_A_B = 3; - /* protected */ var $a = "\n"; - /* protected */ var $b = ''; - /* protected */ var $input = ''; - /* protected */ var $inputIndex = 0; - /* protected */ var $inputLength = 0; - /* protected */ var $lookAhead = null; - /* protected */ var $output = ''; + protected $a = "\n"; + protected $b = ''; + protected $input = ''; + protected $inputIndex = 0; + protected $inputLength = 0; + protected $lookAhead = null; + protected $output = ''; /** * Perform minification, return result */ - /* public*/ function minify($input) + public function minify($input) { $this->input = str_replace("\r\n", "\n", $input); $this->inputLength = strlen($this->input); if ($this->output !== '') { // min already run return $this->output; } - $this->action(JSM_ACTION_DELETE_A_B/*self::ACTION_DELETE_A_B*/); + $this->action(self::ACTION_DELETE_A_B); while ($this->a !== null) { // determine next command - $command = JSM_ACTION_KEEP_A/*self::ACTION_KEEP_A*/; // default + $command = self::ACTION_KEEP_A; // default if ($this->a === ' ') { if (! $this->isAlphaNum($this->b)) { - $command = JSM_ACTION_DELETE_A/*self::ACTION_DELETE_A*/; + $command = self::ACTION_DELETE_A; } } elseif ($this->a === "\n") { if ($this->b === ' ') { - $command = JSM_ACTION_DELETE_A_B/*self::ACTION_DELETE_A_B*/; + $command = self::ACTION_DELETE_A_B; } elseif (false === strpos('{[(+-', $this->b) && ! $this->isAlphaNum($this->b)) { - $command = JSM_ACTION_DELETE_A/*self::ACTION_DELETE_A*/; + $command = self::ACTION_DELETE_A; } } elseif (! $this->isAlphaNum($this->a)) { if ($this->b === ' ' || ($this->b === "\n" && (false === strpos('}])+-"\'', $this->a)))) { - $command = JSM_ACTION_DELETE_A_B/*self::ACTION_DELETE_A_B*/; + $command = self::ACTION_DELETE_A_B; } } $this->action($command); @@ -117,13 +111,13 @@ * ACTION_DELETE_A = Copy B to A. Get the next B. * ACTION_DELETE_A_B = Get the next B. */ - /* protected */ function action($command) + protected function action($command) { switch ($command) { - case JSM_ACTION_KEEP_A/*self::ACTION_KEEP_A*/: + case self::ACTION_KEEP_A: $this->output .= $this->a; // fallthrough - case JSM_ACTION_DELETE_A/*self::ACTION_DELETE_A*/: + case self::ACTION_DELETE_A: $this->a = $this->b; if ($this->a === "'" || $this->a === '"') { // string literal $str = $this->a; // in case needed for exception @@ -133,8 +127,8 @@ if ($this->a === $this->b) { // end quote break; } - if (ord($this->a) <= JSM_ORD_LF/*self::ORD_LF*/) { - trigger_error('Unterminated String: ' . var_export($str, true), E_USER_ERROR); + if (ord($this->a) <= self::ORD_LF) { + throw new Exception('Unterminated String: ' . var_export($str, true)); } $str .= $this->a; if ($this->a === '\\') { @@ -145,7 +139,7 @@ } } // fallthrough - case JSM_ACTION_DELETE_A_B/*self::ACTION_DELETE_A_B*/: + case self::ACTION_DELETE_A_B: $this->b = $this->next(); if ($this->b === '/' && $this->isRegexpLiteral()) { // RegExp literal $this->output .= $this->a . $this->b; @@ -159,8 +153,8 @@ $this->output .= $this->a; $this->a = $this->get(); $pattern .= $this->a; - } elseif (ord($this->a) <= JSM_ORD_LF/*self::ORD_LF*/) { - trigger_error('Unterminated RegExp: '. var_export($pattern, true), E_USER_ERROR); + } elseif (ord($this->a) <= self::ORD_LF) { + throw new Exception('Unterminated RegExp: '. var_export($pattern, true)); } $this->output .= $this->a; } @@ -170,7 +164,7 @@ } } - /* protected */ function isRegexpLiteral() + protected function isRegexpLiteral() { if (false !== strpos("\n{;(,=:[!&|?", $this->a)) { // we aren't dividing return true; @@ -198,7 +192,7 @@ /** * Get next char. Convert ctrl char to space. */ - /* protected */ function get() + protected function get() { $c = $this->lookAhead; $this->lookAhead = null; @@ -213,7 +207,7 @@ if ($c === "\r" || $c === "\n") { return "\n"; } - if (ord($c) < JSM_ORD_SPACE/*self::ORD_SPACE*/) { // control char + if (ord($c) < self::ORD_SPACE) { // control char return ' '; } return $c; @@ -222,7 +216,7 @@ /** * Get next char. If is ctrl character, translate to a space or newline. */ - /* protected */ function peek() + protected function peek() { $this->lookAhead = $this->get(); return $this->lookAhead; @@ -231,18 +225,18 @@ /** * Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII? */ - /* protected */ function isAlphaNum($c) + protected function isAlphaNum($c) { return (preg_match('/^[0-9a-zA-Z_\\$\\\\]$/', $c) || ord($c) > 126); } - /* protected */ function singleLineComment() + protected function singleLineComment() { $comment = ''; while (true) { $get = $this->get(); $comment .= $get; - if (ord($get) <= JSM_ORD_LF/*self::ORD_LF*/) { // EOL reached + if (ord($get) <= self::ORD_LF) { // EOL reached // if IE conditional comment if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) { return "/{$comment}"; @@ -252,7 +246,7 @@ } } - /* protected */ function multipleLineComment() + protected function multipleLineComment() { $this->get(); $comment = ''; @@ -272,7 +266,7 @@ return ' '; } } elseif ($get === null) { - trigger_error('Unterminated Comment: ' . var_export('/*' . $comment, true), E_USER_ERROR); + throw new Exception('Unterminated Comment: ' . var_export('/*' . $comment, true)); } $comment .= $get; } @@ -282,7 +276,7 @@ * Get the next character, skipping over comments. * Some comments may be preserved. */ - /* protected */ function next() + protected function next() { $get = $this->get(); if ($get !== '/') {