PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | vendor/mrclay/jsmin-php/src/JSMin/JSMin.php +23 -18 3.2.3 → 4.7.0 View file →
@@ -56,10 +56,8 @@
56 56 * @license http://opensource.org/licenses/mit-license.php MIT License
57 57 * @link http://code.google.com/p/jsmin-php/
58 58 */
59 59 class JSMin {
60 - const ORD_LF = 10;
61 - const ORD_SPACE = 32;
62 60 const ACTION_KEEP_A = 1;
63 61 const ACTION_DELETE_A = 2;
64 62 const ACTION_DELETE_A_B = 3;
65 63
@@ -122,9 +120,9 @@
122 120
123 121 while ($this->a !== null) {
124 122 // determine next command
125 123 $command = self::ACTION_KEEP_A; // default
126 - if ($this->a === ' ') {
124 + if ($this->isWhiteSpace($this->a)) {
127 125 if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
128 126 && ($this->b === $this->lastByteOut)) {
129 127 // Don't delete this space. If we do, the addition/subtraction
130 128 // could be parsed as a post-increment
@@ -130,23 +128,23 @@
130 128 // could be parsed as a post-increment
131 129 } elseif (! $this->isAlphaNum($this->b)) {
132 130 $command = self::ACTION_DELETE_A;
133 131 }
134 - } elseif ($this->a === "\n") {
135 - if ($this->b === ' ') {
132 + } elseif ($this->isLineTerminator($this->a)) {
133 + if ($this->isWhiteSpace($this->b)) {
136 134 $command = self::ACTION_DELETE_A_B;
137 135
138 136 // in case of mbstring.func_overload & 2, must check for null b,
139 137 // otherwise mb_strpos will give WARNING
140 138 } elseif ($this->b === null
141 - || (false === strpos('{[(+-!~', $this->b)
139 + || (false === strpos('{[(+-!~#', $this->b)
142 140 && ! $this->isAlphaNum($this->b))) {
143 141 $command = self::ACTION_DELETE_A;
144 142 }
145 143 } elseif (! $this->isAlphaNum($this->a)) {
146 - if ($this->b === ' '
147 - || ($this->b === "\n"
148 - && (false === strpos('}])+-"\'', $this->a)))) {
144 + if ($this->isWhiteSpace($this->b)
145 + || ($this->isLineTerminator($this->b)
146 + && (false === strpos('}])+-"\'`', $this->a)))) {
149 147 $command = self::ACTION_DELETE_A_B;
150 148 }
151 149 }
152 150 $this->action($command);
@@ -206,9 +204,9 @@
206 204 $this->a = $this->get();
207 205 if ($this->a === $this->b) { // end quote
208 206 break;
209 207 }
210 - if ($delimiter === '`' && $this->a === "\n") {
208 + if ($delimiter === '`' && $this->isLineTerminator($this->a)) {
211 209 // leave the newline
212 210 } elseif ($this->isEOF($this->a)) {
213 211 $byte = $this->inputIndex - 1;
214 212 throw new UnterminatedStringException(
@@ -286,9 +284,9 @@
286 284 }
287 285
288 286 // check if first non-ws token is "/" (see starts-regex.js)
289 287 $length = strlen($this->output);
290 - if ($this->a === ' ' || $this->a === "\n") {
288 + if ($this->isWhiteSpace($this->a) || $this->isLineTerminator($this->a)) {
291 289 if ($length < 2) { // weird edge case
292 290 return true;
293 291 }
294 292 }
@@ -308,9 +306,9 @@
308 306 return false;
309 307 }
310 308
311 309 // it's a regexp. Remove unneeded whitespace after keyword
312 - if ($this->a === ' ' || $this->a === "\n") {
310 + if ($this->isWhiteSpace($this->a) || $this->isLineTerminator($this->a)) {
313 311 $this->a = '';
314 312 }
315 313
316 314 return true;
@@ -334,15 +332,12 @@
334 332 } else {
335 333 $c = null;
336 334 }
337 335 }
338 - if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
339 - return $c;
340 - }
341 336 if ($c === "\r") {
342 337 return "\n";
343 338 }
344 - return ' ';
339 + return $c;
345 340 }
346 341
347 342 /**
348 343 * Does $a indicate end of input?
@@ -351,9 +346,9 @@
351 346 * @return bool
352 347 */
353 348 protected function isEOF($a)
354 349 {
355 - return ord($a) <= self::ORD_LF;
350 + return $a === null || $this->isLineTerminator($a);
356 351 }
357 352
358 353 /**
359 354 * Get next char (without getting it). If is ctrl character, translate to a space or newline.
@@ -386,9 +381,9 @@
386 381 $comment = '';
387 382 while (true) {
388 383 $get = $this->get();
389 384 $comment .= $get;
390 - if (ord($get) <= self::ORD_LF) { // end of line reached
385 + if ($this->isEOF($get)) {
391 386 // if IE conditional comment
392 387 if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
393 388 $this->keptComment .= "/{$comment}";
394 389 }
@@ -452,6 +447,16 @@
452 447 break;
453 448 }
454 449 }
455 450 return $get;
451 + }
452 +
453 + protected function isWhiteSpace($s) {
454 + // https://www.ecma-international.org/ecma-262/#sec-white-space
455 + return $s !== null && strpos(" \t\v\f", $s) !== false;
456 + }
457 +
458 + protected function isLineTerminator($s) {
459 + // https://www.ecma-international.org/ecma-262/#sec-line-terminators
460 + return $s !== null && strpos("\n\r", $s) !== false;
456 461 }
457 462 }