Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+53
-48
@@ -74,6 +74,11 @@ class Minifier
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* These characters are used to define strings.
|
||||
*/
|
||||
protected $stringDelimiters = ['\'', '"', '`'];
|
||||
|
||||
/**
|
||||
* Contains the default options for minification. This array is merged with
|
||||
* the one passed in by the user to create the request specific set of
|
||||
@@ -115,9 +120,7 @@ class Minifier
|
||||
unset($jshrink);
|
||||
|
||||
return $js;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
if (isset($jshrink)) {
|
||||
// Since the breakdownScript function probably wasn't finished
|
||||
// we clean it out before discarding it.
|
||||
@@ -176,12 +179,11 @@ class Minifier
|
||||
protected function loop()
|
||||
{
|
||||
while ($this->a !== false && !is_null($this->a) && $this->a !== '') {
|
||||
|
||||
switch ($this->a) {
|
||||
// new lines
|
||||
case "\n":
|
||||
// if the next line is something that can't stand alone preserve the newline
|
||||
if (strpos('(-+{[@', $this->b) !== false) {
|
||||
if ($this->b !== false && strpos('(-+[@', $this->b) !== false) {
|
||||
echo $this->a;
|
||||
$this->saveString();
|
||||
break;
|
||||
@@ -189,14 +191,17 @@ class Minifier
|
||||
|
||||
// if B is a space we skip the rest of the switch block and go down to the
|
||||
// string/regex check below, resetting $this->b with getReal
|
||||
if($this->b === ' ')
|
||||
if ($this->b === ' ') {
|
||||
break;
|
||||
}
|
||||
|
||||
// otherwise we treat the newline like a space
|
||||
|
||||
// no break
|
||||
case ' ':
|
||||
if(static::isAlphaNumeric($this->b))
|
||||
if (static::isAlphaNumeric($this->b)) {
|
||||
echo $this->a;
|
||||
}
|
||||
|
||||
$this->saveString();
|
||||
break;
|
||||
@@ -217,14 +222,16 @@ class Minifier
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
if(!static::isAlphaNumeric($this->a))
|
||||
if (!static::isAlphaNumeric($this->a)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// no break
|
||||
default:
|
||||
// check for some regex that breaks stuff
|
||||
if ($this->a === '/' && ($this->b === '\'' || $this->b === '"')) {
|
||||
$this->saveRegex();
|
||||
continue;
|
||||
continue 3;
|
||||
}
|
||||
|
||||
echo $this->a;
|
||||
@@ -236,8 +243,9 @@ class Minifier
|
||||
// do reg check of doom
|
||||
$this->b = $this->getReal();
|
||||
|
||||
if(($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false))
|
||||
if (($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false)) {
|
||||
$this->saveRegex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,9 +274,8 @@ class Minifier
|
||||
if (isset($this->c)) {
|
||||
$char = $this->c;
|
||||
unset($this->c);
|
||||
|
||||
// Otherwise we start pulling from the input.
|
||||
} else {
|
||||
// Otherwise we start pulling from the input.
|
||||
$char = substr($this->input, $this->index, 1);
|
||||
|
||||
// If the next character doesn't exist return false.
|
||||
@@ -282,9 +289,9 @@ class Minifier
|
||||
|
||||
// Normalize all whitespace except for the newline character into a
|
||||
// standard space.
|
||||
if($char !== "\n" && ord($char) < 32)
|
||||
|
||||
if ($char !== "\n" && ord($char) < 32) {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
return $char;
|
||||
}
|
||||
@@ -312,10 +319,13 @@ class Minifier
|
||||
$this->c = $this->getChar();
|
||||
|
||||
if ($this->c === '/') {
|
||||
return $this->processOneLineComments($startIndex);
|
||||
$this->processOneLineComments($startIndex);
|
||||
|
||||
return $this->getReal();
|
||||
} elseif ($this->c === '*') {
|
||||
return $this->processMultiLineComments($startIndex);
|
||||
$this->processMultiLineComments($startIndex);
|
||||
|
||||
return $this->getReal();
|
||||
}
|
||||
|
||||
return $char;
|
||||
@@ -325,8 +335,8 @@ class Minifier
|
||||
* Removed one line comments, with the exception of some very specific types of
|
||||
* conditional comments.
|
||||
*
|
||||
* @param int $startIndex The index point where "getReal" function started
|
||||
* @return string
|
||||
* @param int $startIndex The index point where "getReal" function started
|
||||
* @return void
|
||||
*/
|
||||
protected function processOneLineComments($startIndex)
|
||||
{
|
||||
@@ -335,17 +345,12 @@ class Minifier
|
||||
// kill rest of line
|
||||
$this->getNext("\n");
|
||||
|
||||
unset($this->c);
|
||||
|
||||
if ($thirdCommentString == '@') {
|
||||
$endPoint = $this->index - $startIndex;
|
||||
unset($this->c);
|
||||
$char = "\n" . substr($this->input, $startIndex, $endPoint);
|
||||
} else {
|
||||
// first one is contents of $this->c
|
||||
$this->getChar();
|
||||
$char = $this->getChar();
|
||||
$this->c = "\n" . substr($this->input, $startIndex, $endPoint);
|
||||
}
|
||||
|
||||
return $char;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,7 +358,7 @@ class Minifier
|
||||
* Conditional comments and "license" style blocks are preserved.
|
||||
*
|
||||
* @param int $startIndex The index point where "getReal" function started
|
||||
* @return bool|string False if there's no character
|
||||
* @return void
|
||||
* @throws \RuntimeException Unclosed comments will throw an error
|
||||
*/
|
||||
protected function processMultiLineComments($startIndex)
|
||||
@@ -363,14 +368,13 @@ class Minifier
|
||||
|
||||
// kill everything up to the next */ if it's there
|
||||
if ($this->getNext('*/')) {
|
||||
|
||||
$this->getChar(); // get *
|
||||
$this->getChar(); // get /
|
||||
$char = $this->getChar(); // get next real character
|
||||
|
||||
// Now we reinsert conditional comments and YUI-style licensing comments
|
||||
if (($this->options['flaggedComments'] && $thirdCommentString === '!')
|
||||
|| ($thirdCommentString === '@') ) {
|
||||
|| ($thirdCommentString === '@')) {
|
||||
|
||||
// If conditional comments or flagged comments are not the first thing in the script
|
||||
// we need to echo a and fill it with a space before moving on.
|
||||
@@ -387,21 +391,20 @@ class Minifier
|
||||
$endPoint = ($this->index - 1) - $startIndex;
|
||||
echo substr($this->input, $startIndex, $endPoint);
|
||||
|
||||
return $char;
|
||||
}
|
||||
$this->c = $char;
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$char = false;
|
||||
}
|
||||
|
||||
if($char === false)
|
||||
if ($char === false) {
|
||||
throw new \RuntimeException('Unclosed multiline comment at position: ' . ($this->index - 2));
|
||||
}
|
||||
|
||||
// if we're here c is part of the comment and therefore tossed
|
||||
if(isset($this->c))
|
||||
unset($this->c);
|
||||
|
||||
return $char;
|
||||
$this->c = $char;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,9 +421,9 @@ class Minifier
|
||||
$pos = strpos($this->input, $string, $this->index);
|
||||
|
||||
// If it's not there return false.
|
||||
if($pos === false)
|
||||
|
||||
if ($pos === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adjust position of index to jump ahead to the asked for string
|
||||
$this->index = $pos;
|
||||
@@ -444,7 +447,7 @@ class Minifier
|
||||
$this->a = $this->b;
|
||||
|
||||
// If this isn't a string we don't need to do anything.
|
||||
if ($this->a !== "'" && $this->a !== '"') {
|
||||
if (!in_array($this->a, $this->stringDelimiters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -455,11 +458,8 @@ class Minifier
|
||||
echo $this->a;
|
||||
|
||||
// Loop until the string is done
|
||||
while (true) {
|
||||
|
||||
// Grab the very next character and load it into a
|
||||
$this->a = $this->getChar();
|
||||
|
||||
// Grab the very next character and load it into a
|
||||
while (($this->a = $this->getChar()) !== false) {
|
||||
switch ($this->a) {
|
||||
|
||||
// If the string opener (single or double quote) is used
|
||||
@@ -473,7 +473,11 @@ class Minifier
|
||||
// character, so those will be treated just fine using the switch
|
||||
// block below.
|
||||
case "\n":
|
||||
throw new \RuntimeException('Unclosed string at position: ' . $startpos );
|
||||
if ($stringType === '`') {
|
||||
echo $this->a;
|
||||
} else {
|
||||
throw new \RuntimeException('Unclosed string at position: ' . $startpos);
|
||||
}
|
||||
break;
|
||||
|
||||
// Escaped characters get picked up here. If it's an escaped new line it's not really needed
|
||||
@@ -513,16 +517,18 @@ class Minifier
|
||||
echo $this->a . $this->b;
|
||||
|
||||
while (($this->a = $this->getChar()) !== false) {
|
||||
if($this->a === '/')
|
||||
if ($this->a === '/') {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->a === '\\') {
|
||||
echo $this->a;
|
||||
$this->a = $this->getChar();
|
||||
}
|
||||
|
||||
if($this->a === "\n")
|
||||
if ($this->a === "\n") {
|
||||
throw new \RuntimeException('Unclosed regex pattern at position: ' . $this->index);
|
||||
}
|
||||
|
||||
echo $this->a;
|
||||
}
|
||||
@@ -583,5 +589,4 @@ class Minifier
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user