mirror of
https://github.com/mrclay/minify.git
synced 2025-08-10 16:14:18 +02:00
move cc-checking to constructor
This commit is contained in:
@@ -70,34 +70,30 @@ class JSMin {
|
|||||||
protected $output = '';
|
protected $output = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minify Javascript
|
* Minify Javascript.
|
||||||
*
|
*
|
||||||
* @param string $js Javascript to be minified
|
* @param string $js Javascript to be minified
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function minify($js)
|
public static function minify($js)
|
||||||
{
|
{
|
||||||
// look out for syntax like "++ +" and "- ++"
|
|
||||||
$p = '\\+';
|
|
||||||
$m = '\\-';
|
|
||||||
if (preg_match("/([$p$m])(?:\\1 [$p$m]| (?:$p$p|$m$m))/", $js)) {
|
|
||||||
// likely pre-minified and would be broken by JSMin
|
|
||||||
return $js;
|
|
||||||
}
|
|
||||||
$jsmin = new JSMin($js);
|
$jsmin = new JSMin($js);
|
||||||
return $jsmin->min();
|
return $jsmin->min();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Don't create a JSMin instance, instead use the static function minify,
|
* @param string $input
|
||||||
* which checks for mb_string function overloading and avoids errors
|
|
||||||
* trying to re-minify the output of Closure Compiler
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
public function __construct($input)
|
public function __construct($input)
|
||||||
{
|
{
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
|
// look out for syntax like "++ +" and "- ++"
|
||||||
|
$p = '\\+';
|
||||||
|
$m = '\\-';
|
||||||
|
if (preg_match("/([$p$m])(?:\\1 [$p$m]| (?:$p$p|$m$m))/", $input)) {
|
||||||
|
// likely pre-minified and would be broken by JSMin
|
||||||
|
$this->output = $input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user