| 1 |
<?php |
| 2 |
|
| 3 |
namespace MatthiasMullie\Minify\Test; |
| 4 |
|
| 5 |
use PHPUnit\Framework\TestCase; |
| 6 |
|
| 7 |
/** |
| 8 |
* JS minifier test case. |
| 9 |
*/ |
| 10 |
class JSTest extends TestCase |
| 11 |
{ |
| 12 |
protected function mockMinifier() |
| 13 |
{ |
| 14 |
// override save method, there's no point in writing the result out here |
| 15 |
return $this->getMockBuilder('\MatthiasMullie\Minify\JS') |
| 16 |
->setMethods(array('save')) |
| 17 |
->getMock(); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Test minifier on files that doesn't exist. |
| 22 |
*/ |
| 23 |
public function testAddFileException() |
| 24 |
{ |
| 25 |
$this->expectException('MatthiasMullie\Minify\Exceptions\IOException'); |
| 26 |
|
| 27 |
$minifier = $this->mockMinifier(); |
| 28 |
$minifier->addFile('/sample/source/nothing'); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Test minifier addFile method. |
| 33 |
*/ |
| 34 |
public function testAddFile() |
| 35 |
{ |
| 36 |
$minifier = $this->mockMinifier(); |
| 37 |
$minifier->addFile(__DIR__.'/sample/source/script1.js'); |
| 38 |
|
| 39 |
$result = $minifier->minify(); |
| 40 |
|
| 41 |
$this->assertEquals('var test=1', $result); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Test JS minifier rules, provided by dataProvider. |
| 46 |
* |
| 47 |
* @dataProvider dataProvider |
| 48 |
*/ |
| 49 |
public function testMinify($input, $expected) |
| 50 |
{ |
| 51 |
$minifier = $this->mockMinifier(); |
| 52 |
$minifier->add($input); |
| 53 |
$result = $minifier->minify(); |
| 54 |
|
| 55 |
$this->assertEquals($expected, $result); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* @return array [input, expected result] |
| 60 |
*/ |
| 61 |
public function dataProvider() |
| 62 |
{ |
| 63 |
$tests = array(); |
| 64 |
|
| 65 |
// adding multiple files |
| 66 |
$tests[] = array( |
| 67 |
array( |
| 68 |
__DIR__.'/sample/source/script1.js', |
| 69 |
__DIR__.'/sample/source/script2.js', |
| 70 |
), |
| 71 |
'var test=1;var test=2', |
| 72 |
); |
| 73 |
|
| 74 |
// adding multiple files and string |
| 75 |
$tests[] = array( |
| 76 |
array( |
| 77 |
__DIR__.'/sample/source/script1.js', |
| 78 |
'console.log(test)', |
| 79 |
__DIR__.'/sample/source/script2.js', |
| 80 |
), |
| 81 |
'var test=1;console.log(test);var test=2', |
| 82 |
); |
| 83 |
|
| 84 |
// escaped quotes should not terminate string |
| 85 |
$tests[] = array( |
| 86 |
'alert("Escaped quote which is same as string quotes: \"; should not match")', |
| 87 |
'alert("Escaped quote which is same as string quotes: \"; should not match")', |
| 88 |
); |
| 89 |
|
| 90 |
// backtick string (allow string interpolation) |
| 91 |
$tests[] = array( |
| 92 |
'var str=`Hi, ${name}`', |
| 93 |
'var str=`Hi, ${name}`', |
| 94 |
); |
| 95 |
|
| 96 |
// regex delimiters need to be treated as strings |
| 97 |
// (two forward slashes could look like a comment) |
| 98 |
$tests[] = array( |
| 99 |
'/abc\/def\//.test("abc")', |
| 100 |
'/abc\/def\//.test("abc")', |
| 101 |
); |
| 102 |
$tests[] = array( |
| 103 |
'/abc\/def\//.test("abc\/def\/")', |
| 104 |
'/abc\/def\//.test("abc\/def\/")', |
| 105 |
); |
| 106 |
$tests[] = array( |
| 107 |
// there's an escape mess here; below regex represent this JS line: |
| 108 |
// /abc\/def\\\//.test("abc/def\\/") |
| 109 |
'/abc\/def\\\\\//.test("abc/def\\\/")', |
| 110 |
'/abc\/def\\\\\//.test("abc/def\\\/")', |
| 111 |
); |
| 112 |
$tests[] = array( |
| 113 |
// escape mess, this represents: |
| 114 |
// /abc\/def\\\\\//.test("abc/def\\\\/") |
| 115 |
'/abc\/def\\\\\\\\\//.test("abc/def\\\\\\\\/")', |
| 116 |
'/abc\/def\\\\\\\\\//.test("abc/def\\\\\\\\/")', |
| 117 |
); |
| 118 |
$tests[] = array( |
| 119 |
'var a = /abc\/def\//.test("abc")', |
| 120 |
'var a=/abc\/def\//.test("abc")', |
| 121 |
); |
| 122 |
|
| 123 |
// don't confuse multiple slashes for regexes |
| 124 |
$tests[] = array( |
| 125 |
'a = b / c; d = e / f', |
| 126 |
'a=b/c;d=e/f', |
| 127 |
); |
| 128 |
$tests[] = array( |
| 129 |
'(2 + 4) / 3 + 5 / 1', |
| 130 |
'(2+4)/3+5/1', |
| 131 |
); |
| 132 |
|
| 133 |
$tests[] = array( |
| 134 |
'a=4/ |
| 135 |
2', |
| 136 |
'a=4/2', |
| 137 |
); |
| 138 |
|
| 139 |
// mixture of quotes starting in comment/regex, to make sure strings are |
| 140 |
// matched correctly, not inside comment/regex |
| 141 |
// additionally test catching of empty strings as well |
| 142 |
$tests[] = array( |
| 143 |
'/abc"def/.test("abc")', |
| 144 |
'/abc"def/.test("abc")', |
| 145 |
); |
| 146 |
$tests[] = array( |
| 147 |
'/abc"def/.test(\'\')', |
| 148 |
'/abc"def/.test(\'\')', |
| 149 |
); |
| 150 |
|
| 151 |
$tests[] = array( |
| 152 |
'/* Bogus " */var test="test";', |
| 153 |
'var test="test"', |
| 154 |
); |
| 155 |
|
| 156 |
// replace comments |
| 157 |
$tests[] = array( |
| 158 |
'/* This is a JS comment */', |
| 159 |
'', |
| 160 |
); |
| 161 |
|
| 162 |
// preserve important comments |
| 163 |
$tests[] = array( |
| 164 |
'/*! This is a JS comment */', |
| 165 |
'/*! This is a JS comment */', |
| 166 |
); |
| 167 |
|
| 168 |
$tests[] = array( |
| 169 |
'/*! |
| 170 |
* This is a multi line JS comment |
| 171 |
*/', |
| 172 |
'/*! |
| 173 |
* This is a multi line JS comment |
| 174 |
*/', |
| 175 |
); |
| 176 |
|
| 177 |
$tests[] = array( |
| 178 |
'/* @license This is a JS comment */', |
| 179 |
'/* @license This is a JS comment */', |
| 180 |
); |
| 181 |
|
| 182 |
$tests[] = array( |
| 183 |
'/* @preserve This is a JS comment */', |
| 184 |
'/* @preserve This is a JS comment */', |
| 185 |
); |
| 186 |
|
| 187 |
// make sure no ; is added in places it shouldn't |
| 188 |
$tests[] = array( |
| 189 |
'if(true){}else{}', |
| 190 |
'if(!0){}else{}', |
| 191 |
); |
| 192 |
$tests[] = array( |
| 193 |
'do{i++}while(i<1)', |
| 194 |
'do{i++}while(i<1)', |
| 195 |
); |
| 196 |
|
| 197 |
$tests[] = array( |
| 198 |
'if(true)statement;else statement', |
| 199 |
'if(!0)statement;else statement', |
| 200 |
); |
| 201 |
|
| 202 |
$tests[] = array( |
| 203 |
'for ( i = 0; ; i++ ) statement', |
| 204 |
'for(i=0;;i++)statement', |
| 205 |
); |
| 206 |
$tests[] = array( |
| 207 |
'for (i = 0; (i < 10); i++) statement', |
| 208 |
'for(i=0;(i<10);i++)statement', |
| 209 |
); |
| 210 |
$tests[] = array( |
| 211 |
'alert("test");;alert("test2")', |
| 212 |
'alert("test");alert("test2")', |
| 213 |
); |
| 214 |
$tests[] = array( |
| 215 |
'-1 |
| 216 |
+2', |
| 217 |
'-1+2', |
| 218 |
); |
| 219 |
$tests[] = array( |
| 220 |
'-1+ |
| 221 |
2', |
| 222 |
'-1+2', |
| 223 |
); |
| 224 |
$tests[] = array( |
| 225 |
'alert("this is a test");', |
| 226 |
'alert("this is a test")', |
| 227 |
); |
| 228 |
|
| 229 |
// test where newline should be preserved (for ASI) or semicolon added |
| 230 |
$tests[] = array( |
| 231 |
'function(){console.log("this is a test");}', |
| 232 |
'function(){console.log("this is a test")}', |
| 233 |
); |
| 234 |
$tests[] = array( |
| 235 |
'alert("this is a test") |
| 236 |
alert("this is another test")', |
| 237 |
'alert("this is a test") |
| 238 |
alert("this is another test")', |
| 239 |
); |
| 240 |
$tests[] = array( |
| 241 |
'a=b+c |
| 242 |
d=e+f', |
| 243 |
'a=b+c |
| 244 |
d=e+f', |
| 245 |
); |
| 246 |
$tests[] = array( |
| 247 |
'a++ |
| 248 |
|
| 249 |
++b', |
| 250 |
'a++ |
| 251 |
++b', |
| 252 |
); |
| 253 |
$tests[] = array( |
| 254 |
'!a |
| 255 |
!b', |
| 256 |
'!a |
| 257 |
!b', |
| 258 |
); |
| 259 |
$tests[] = array( |
| 260 |
// don't confuse with 'if' |
| 261 |
'digestif |
| 262 |
(true) |
| 263 |
statement', |
| 264 |
'digestif(!0) |
| 265 |
statement', |
| 266 |
); |
| 267 |
$tests[] = array( |
| 268 |
'if |
| 269 |
( |
| 270 |
( |
| 271 |
true |
| 272 |
) |
| 273 |
&& |
| 274 |
( |
| 275 |
true |
| 276 |
) |
| 277 |
) |
| 278 |
statement', |
| 279 |
'if((!0)&&(!0)) |
| 280 |
statement', |
| 281 |
); |
| 282 |
$tests[] = array( |
| 283 |
'if |
| 284 |
( |
| 285 |
true |
| 286 |
) |
| 287 |
{ |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
}', |
| 292 |
'if(!0){}else{}', |
| 293 |
); |
| 294 |
$tests[] = array( |
| 295 |
'do |
| 296 |
{ |
| 297 |
i++ |
| 298 |
} |
| 299 |
while |
| 300 |
( |
| 301 |
i<1 |
| 302 |
)', |
| 303 |
'do{i++} |
| 304 |
while(i<1)', |
| 305 |
); |
| 306 |
$tests[] = array( |
| 307 |
'if ( true ) |
| 308 |
statement |
| 309 |
else |
| 310 |
statement', |
| 311 |
'if(!0) |
| 312 |
statement |
| 313 |
else statement', |
| 314 |
); |
| 315 |
|
| 316 |
// test if whitespace around keywords is properly collapsed |
| 317 |
$tests[] = array( |
| 318 |
'var |
| 319 |
variable |
| 320 |
= |
| 321 |
"value";', |
| 322 |
'var variable="value"', |
| 323 |
); |
| 324 |
$tests[] = array( |
| 325 |
'var variable = { |
| 326 |
test: |
| 327 |
{ |
| 328 |
} |
| 329 |
}', |
| 330 |
'var variable={test:{}}', |
| 331 |
); |
| 332 |
$tests[] = array( |
| 333 |
'if ( true ) { |
| 334 |
} else { |
| 335 |
}', |
| 336 |
'if(!0){}else{}', |
| 337 |
); |
| 338 |
$tests[] = array( |
| 339 |
'53 instanceof String', |
| 340 |
'53 instanceof String', |
| 341 |
); |
| 342 |
|
| 343 |
// remove whitespace around operators |
| 344 |
$tests[] = array( |
| 345 |
'a = 1 + 2', |
| 346 |
'a=1+2', |
| 347 |
); |
| 348 |
$tests[] = array( |
| 349 |
'object . property', |
| 350 |
'object.property', |
| 351 |
); |
| 352 |
$tests[] = array( |
| 353 |
'object |
| 354 |
.property', |
| 355 |
'object.property', |
| 356 |
); |
| 357 |
$tests[] = array( |
| 358 |
'alert ( "this is a test" );', |
| 359 |
'alert("this is a test")', |
| 360 |
); |
| 361 |
|
| 362 |
// mix of ++ and +: three consecutive +es will be interpreted as ++ + |
| 363 |
$tests[] = array( |
| 364 |
'a++ +b', |
| 365 |
'a++ +b', |
| 366 |
); |
| 367 |
$tests[] = array( |
| 368 |
'a+ ++b', |
| 369 |
'a+ ++b', // +++ would actually be allowed as well |
| 370 |
); |
| 371 |
|
| 372 |
// SyntaxError: identifier starts immediately after numeric literal |
| 373 |
$tests[] = array( |
| 374 |
'42 .toString()', |
| 375 |
'42 .toString()', |
| 376 |
); |
| 377 |
|
| 378 |
// add comment in between whitespace that needs to be stripped |
| 379 |
$tests[] = array( |
| 380 |
'object |
| 381 |
// haha, some comment, just to make things harder! |
| 382 |
.property', |
| 383 |
'object.property', |
| 384 |
); |
| 385 |
|
| 386 |
// add comment in between whitespace that needs to be stripped |
| 387 |
$tests[] = array( |
| 388 |
'var test=true,test2=false', |
| 389 |
'var test=!0,test2=!1', |
| 390 |
); |
| 391 |
$tests[] = array( |
| 392 |
'var testtrue="testing if true as part of varname is ignored as it should"', |
| 393 |
'var testtrue="testing if true as part of varname is ignored as it should"', |
| 394 |
); |
| 395 |
|
| 396 |
// random bits of code that tripped errors during development |
| 397 |
$tests[] = array( |
| 398 |
' |
| 399 |
// check if it isn\'t a text-element |
| 400 |
if(currentElement.attr(\'type\') != \'text\') |
| 401 |
{ |
| 402 |
// remove the current one |
| 403 |
currentElement.remove(); |
| 404 |
} |
| 405 |
|
| 406 |
// already a text element |
| 407 |
else newElement = currentElement; |
| 408 |
', |
| 409 |
'if(currentElement.attr(\'type\')!=\'text\'){currentElement.remove()}else newElement=currentElement', |
| 410 |
); |
| 411 |
$tests[] = array( |
| 412 |
'var jsBackend = |
| 413 |
{ |
| 414 |
debug: false, |
| 415 |
current: {} |
| 416 |
}', |
| 417 |
'var jsBackend={debug:!1,current:{}}', |
| 418 |
); |
| 419 |
$tests[] = array( |
| 420 |
'var utils = |
| 421 |
{ |
| 422 |
debug: false |
| 423 |
} |
| 424 |
utils.array = |
| 425 |
{ |
| 426 |
}', |
| 427 |
'var utils={debug:!1} |
| 428 |
utils.array={}', |
| 429 |
); |
| 430 |
$tests[] = array( |
| 431 |
'rescape = /\'|\\\\/g, |
| 432 |
|
| 433 |
// blablabla here was some more code but the point was that somewhere |
| 434 |
// down below, there would be a closing quote which would cause the |
| 435 |
// regex (confused for escaped closing tag) not to be recognized, |
| 436 |
// taking the opening single quote & looking for a string. |
| 437 |
// So here\'s <-- the closing quote |
| 438 |
runescape = \'blabla\'', |
| 439 |
'rescape=/\'|\\\\/g,runescape=\'blabla\'', |
| 440 |
); |
| 441 |
$tests[] = array( |
| 442 |
'var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/)', |
| 443 |
'var rsingleTag=(/^<(\w+)\s*\/?>(?:<\/\1>|)$/)', |
| 444 |
); |
| 445 |
$tests[] = array( |
| 446 |
'if (this.sliding) return this.$element.one(\'slid.bs.carousel\', function () { that.to(pos) }) // yes, "slid" |
| 447 |
if (activeIndex == pos) return this.pause().cycle()', |
| 448 |
'if(this.sliding)return this.$element.one(\'slid.bs.carousel\',function(){that.to(pos)}) |
| 449 |
if(activeIndex==pos)return this.pause().cycle()', |
| 450 |
); |
| 451 |
$tests[] = array( |
| 452 |
'if (e.which == 38 && index > 0) index-- // up |
| 453 |
if (e.which == 40 && index < $items.length - 1) index++ // down', |
| 454 |
'if(e.which==38&&index>0)index-- |
| 455 |
if(e.which==40&&index<$items.length-1)index++', |
| 456 |
); |
| 457 |
|
| 458 |
// replace associative array key references by property notation |
| 459 |
$tests[] = array( |
| 460 |
'array["key"][\'key2\']', |
| 461 |
'array.key.key2', |
| 462 |
); |
| 463 |
$tests[] = array( |
| 464 |
'array[ "key" ][ \'key2\' ]', |
| 465 |
'array.key.key2', |
| 466 |
); |
| 467 |
$tests[] = array( |
| 468 |
'array["a","b","c"]', |
| 469 |
'array["a","b","c"]', |
| 470 |
); |
| 471 |
|
| 472 |
$tests[] = array( |
| 473 |
"['loader']", |
| 474 |
"['loader']", |
| 475 |
); |
| 476 |
$tests[] = array( |
| 477 |
'array["dont-replace"][\'key2\']', |
| 478 |
'array["dont-replace"].key2', |
| 479 |
); |
| 480 |
|
| 481 |
// shorten bools |
| 482 |
$tests[] = array( |
| 483 |
'while(true){break}', |
| 484 |
'for(;;){break}', |
| 485 |
); |
| 486 |
// make sure we don't get "missing while after do-loop body" |
| 487 |
$tests[] = array( |
| 488 |
'do{break}while(true)', |
| 489 |
'do{break}while(!0)', |
| 490 |
); |
| 491 |
$tests[] = array( |
| 492 |
"do break\nwhile(true)", |
| 493 |
"do break\nwhile(!0)", |
| 494 |
); |
| 495 |
$tests[] = array( |
| 496 |
"do{break}while(true){alert('test')}", |
| 497 |
"do{break}while(!0){alert('test')}", |
| 498 |
); |
| 499 |
$tests[] = array( |
| 500 |
"do break\nwhile(true){alert('test')}", |
| 501 |
"do break\nwhile(!0){alert('test')}", |
| 502 |
); |
| 503 |
// nested do-while & while |
| 504 |
$tests[] = array( |
| 505 |
"do{while(true){break}break}while(true){alert('test')}", |
| 506 |
"do{for(;;){break}break}while(!0){alert('test')}", |
| 507 |
); |
| 508 |
$tests[] = array( |
| 509 |
"do{while(true){break}break}while(true){alert('test')}while(true){break}", |
| 510 |
"do{for(;;){break}break}while(!0){alert('test')}for(;;){break}", |
| 511 |
); |
| 512 |
$tests[] = array( |
| 513 |
"do{while(true){break}break}while(true){alert('test')}while(true){break}do{while(true){break}break}while(true){alert('test')}while(true){break}", |
| 514 |
"do{for(;;){break}break}while(!0){alert('test')}for(;;){break}do{for(;;){break}break}while(!0){alert('test')}for(;;){break}", |
| 515 |
); |
| 516 |
|
| 517 |
// https://github.com/matthiasmullie/minify/issues/10 |
| 518 |
$tests[] = array( |
| 519 |
'// first mutation patch |
| 520 |
// second mutation patch |
| 521 |
// third mutation patch |
| 522 |
// fourth mutation patch', |
| 523 |
'', |
| 524 |
); |
| 525 |
$tests[] = array( |
| 526 |
'///////////////////////// |
| 527 |
// first mutation patch |
| 528 |
// second mutation patch |
| 529 |
// third mutation patch |
| 530 |
// fourth mutation patch |
| 531 |
/////////////////////////', |
| 532 |
'', |
| 533 |
); |
| 534 |
|
| 535 |
// https://github.com/matthiasmullie/minify/issues/14 |
| 536 |
$tests[] = array( |
| 537 |
'function foo (a, b) |
| 538 |
{ |
| 539 |
return a / b; |
| 540 |
} |
| 541 |
function foo (a, b) |
| 542 |
{ |
| 543 |
return a / b; |
| 544 |
}', |
| 545 |
'function foo(a,b){return a/b} |
| 546 |
function foo(a,b){return a/b}', |
| 547 |
); |
| 548 |
|
| 549 |
// https://github.com/matthiasmullie/minify/issues/15 |
| 550 |
$tests[] = array( |
| 551 |
'if ( !data.success ) |
| 552 |
deferred.reject(); else |
| 553 |
deferred.resolve(data);', |
| 554 |
'if(!data.success) |
| 555 |
deferred.reject();else deferred.resolve(data)', |
| 556 |
); |
| 557 |
$tests[] = array( |
| 558 |
"if ( typeof jQuery === 'undefined' ) |
| 559 |
throw new Error('.editManager.js: jQuery is required and must be loaded first');", |
| 560 |
"if(typeof jQuery==='undefined') |
| 561 |
throw new Error('.editManager.js: jQuery is required and must be loaded first')", |
| 562 |
); |
| 563 |
|
| 564 |
// https://github.com/matthiasmullie/minify/issues/27 |
| 565 |
$tests[] = array( |
| 566 |
'$.expr[":"]', |
| 567 |
'$.expr[":"]', |
| 568 |
); |
| 569 |
|
| 570 |
// https://github.com/matthiasmullie/minify/issues/31 |
| 571 |
$tests[] = array( |
| 572 |
"$(_this).attr('src',this.src).trigger('adapt',['loader'])", |
| 573 |
"$(_this).attr('src',this.src).trigger('adapt',['loader'])", |
| 574 |
); |
| 575 |
|
| 576 |
// https://github.com/matthiasmullie/minify/issues/33 |
| 577 |
$tests[] = array( |
| 578 |
'$.fn.alert = Plugin |
| 579 |
$.fn.alert.Constructor = Alert', |
| 580 |
'$.fn.alert=Plugin |
| 581 |
$.fn.alert.Constructor=Alert', |
| 582 |
); |
| 583 |
|
| 584 |
// https://github.com/matthiasmullie/minify/issues/34 |
| 585 |
$tests[] = array( |
| 586 |
'a.replace("\\\\","");hi="This is a string"', |
| 587 |
'a.replace("\\\\","");hi="This is a string"', |
| 588 |
); |
| 589 |
|
| 590 |
// https://github.com/matthiasmullie/minify/issues/35 |
| 591 |
$tests[] = array( |
| 592 |
array( |
| 593 |
'// script that ends with comment', |
| 594 |
'var test=1', |
| 595 |
), |
| 596 |
'var test=1', |
| 597 |
); |
| 598 |
|
| 599 |
// https://github.com/matthiasmullie/minify/issues/37 |
| 600 |
$tests[] = array( |
| 601 |
'function () { ;;;;;;;; }', |
| 602 |
'function(){}', |
| 603 |
); |
| 604 |
|
| 605 |
// https://github.com/matthiasmullie/minify/issues/40 |
| 606 |
$tests[] = array( |
| 607 |
'for(v=1,_=b;;){}', |
| 608 |
'for(v=1,_=b;;){}', |
| 609 |
); |
| 610 |
|
| 611 |
// https://github.com/matthiasmullie/minify/issues/41 |
| 612 |
$tests[] = array( |
| 613 |
"conf.zoomHoverIcons['default']", |
| 614 |
"conf.zoomHoverIcons['default']", |
| 615 |
); |
| 616 |
|
| 617 |
// https://github.com/matthiasmullie/minify/issues/42 |
| 618 |
$tests[] = array( |
| 619 |
'for(i=1;i<2;i++);', |
| 620 |
'for(i=1;i<2;i++);', |
| 621 |
); |
| 622 |
$tests[] = array( |
| 623 |
'if(1){for(i=1;i<2;i++);}', |
| 624 |
'if(1){for(i=1;i<2;i++);}', |
| 625 |
); |
| 626 |
$tests[] = array( |
| 627 |
'for(i in list);', |
| 628 |
'for(i in list);', |
| 629 |
); |
| 630 |
$tests[] = array( |
| 631 |
'if(1){for(i in list);}', |
| 632 |
'if(1){for(i in list);}', |
| 633 |
); |
| 634 |
|
| 635 |
// https://github.com/matthiasmullie/minify/issues/43 |
| 636 |
$tests[] = array( |
| 637 |
'{"key":"3","key2":"value","key3":"3"}', |
| 638 |
'{"key":"3","key2":"value","key3":"3"}', |
| 639 |
); |
| 640 |
|
| 641 |
// https://github.com/matthiasmullie/minify/issues/44 |
| 642 |
$tests[] = array( |
| 643 |
'return ["x"]', |
| 644 |
'return["x"]', |
| 645 |
); |
| 646 |
|
| 647 |
// https://github.com/matthiasmullie/minify/issues/50 |
| 648 |
$tests[] = array( |
| 649 |
'do{var dim=this._getDaysInMonth(year,month-1);if(day<=dim){break}month++;day-=dim}while(true)}', |
| 650 |
'do{var dim=this._getDaysInMonth(year,month-1);if(day<=dim){break}month++;day-=dim}while(!0)}', |
| 651 |
); |
| 652 |
|
| 653 |
// https://github.com/matthiasmullie/minify/issues/53 |
| 654 |
$tests[] = array( |
| 655 |
'a.validator.addMethod("accept", function (b, c, d) { |
| 656 |
var e, f, g = "string" == typeof d ? |
| 657 |
d.replace(/\s/g, "").replace(/,/g, "|") : |
| 658 |
"image/*", h = this.optional(c); |
| 659 |
if (h)return h; |
| 660 |
if ("file" === a(c).attr("type") && (g = g.replace(/\*/g, ".*"), c.files && c.files.length)) |
| 661 |
for (e = 0; e < c.files.length; e++) |
| 662 |
if (f = c.files[e], !f.type.match(new RegExp(".?(" + g + ")$", "i"))) |
| 663 |
return !1; |
| 664 |
return !0 |
| 665 |
}', |
| 666 |
'a.validator.addMethod("accept",function(b,c,d){var e,f,g="string"==typeof d?d.replace(/\s/g,"").replace(/,/g,"|"):"image/*",h=this.optional(c);if(h)return h;if("file"===a(c).attr("type")&&(g=g.replace(/\*/g,".*"),c.files&&c.files.length)) |
| 667 |
for(e=0;e<c.files.length;e++) |
| 668 |
if(f=c.files[e],!f.type.match(new RegExp(".?("+g+")$","i"))) |
| 669 |
return!1;return!0}', |
| 670 |
); |
| 671 |
|
| 672 |
// https://github.com/matthiasmullie/minify/issues/54 |
| 673 |
$tests[] = array( |
| 674 |
'function a() { |
| 675 |
if (true) |
| 676 |
return |
| 677 |
if (false) |
| 678 |
return |
| 679 |
}', |
| 680 |
'function a(){if(!0) |
| 681 |
return |
| 682 |
if(!1) |
| 683 |
return}', |
| 684 |
); |
| 685 |
|
| 686 |
// https://github.com/matthiasmullie/minify/issues/56 |
| 687 |
$tests[] = array( |
| 688 |
'var timeRegex = /^([2][0-3]|[01]?[0-9])(:[0-5][0-9])?$/ |
| 689 |
if (start_time.match(timeRegex) == null) {}', |
| 690 |
'var timeRegex=/^([2][0-3]|[01]?[0-9])(:[0-5][0-9])?$/ |
| 691 |
if(start_time.match(timeRegex)==null){}', |
| 692 |
); |
| 693 |
|
| 694 |
// https://github.com/matthiasmullie/minify/issues/58 |
| 695 |
// stripped of redundant code to expose problem case |
| 696 |
$tests[] = array( |
| 697 |
<<<'BUG' |
| 698 |
function inspect() { |
| 699 |
escapedString.replace(/abc/g, '\\\''); |
| 700 |
} |
| 701 |
function isJSON() { |
| 702 |
str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'); |
| 703 |
} |
| 704 |
BUG |
| 705 |
, |
| 706 |
<<<'BUG' |
| 707 |
function inspect(){escapedString.replace(/abc/g,'\\\'')} |
| 708 |
function isJSON(){str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']')} |
| 709 |
BUG |
| 710 |
); |
| 711 |
|
| 712 |
// https://github.com/matthiasmullie/minify/issues/59 |
| 713 |
$tests[] = array( |
| 714 |
'isPath:function(e) { |
| 715 |
return /\//.test(e); |
| 716 |
}', |
| 717 |
'isPath:function(e){return/\//.test(e)}', |
| 718 |
); |
| 719 |
|
| 720 |
// https://github.com/matthiasmullie/minify/issues/64 |
| 721 |
$tests[] = array( |
| 722 |
' var d3_nsPrefix = { |
| 723 |
svg: "http://www.w3.org/2000/svg", |
| 724 |
xhtml: "http://www.w3.org/1999/xhtml", |
| 725 |
xlink: "http://www.w3.org/1999/xlink", |
| 726 |
xml: "http://www.w3.org/XML/1998/namespace", |
| 727 |
xmlns: "http://www.w3.org/2000/xmlns/" |
| 728 |
};', |
| 729 |
'var d3_nsPrefix={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"}', |
| 730 |
); |
| 731 |
|
| 732 |
// https://github.com/matthiasmullie/minify/issues/66 |
| 733 |
$tests[] = array( |
| 734 |
"$(coming.wrap).bind('onReset', function () { |
| 735 |
try { |
| 736 |
$(this).find('iframe').hide().attr('src', '//about:blank').end().empty(); |
| 737 |
} catch (e) {} |
| 738 |
});", |
| 739 |
"$(coming.wrap).bind('onReset',function(){try{\$(this).find('iframe').hide().attr('src','//about:blank').end().empty()}catch(e){}})", |
| 740 |
); |
| 741 |
|
| 742 |
// https://github.com/matthiasmullie/minify/issues/89 |
| 743 |
$tests[] = array( |
| 744 |
'for(;;ja||(ja=true)){}', |
| 745 |
'for(;;ja||(ja=!0)){}', |
| 746 |
); |
| 747 |
|
| 748 |
// https://github.com/matthiasmullie/minify/issues/91 |
| 749 |
$tests[] = array( |
| 750 |
'if(true){if(true)console.log("test")else;}', |
| 751 |
'if(!0){if(!0)console.log("test")}', |
| 752 |
); |
| 753 |
|
| 754 |
// https://github.com/matthiasmullie/minify/issues/99 |
| 755 |
$tests[] = array( |
| 756 |
'"object";"object2";"0";"1"', |
| 757 |
'"object";"object2";"0";"1"', |
| 758 |
); |
| 759 |
|
| 760 |
// https://github.com/matthiasmullie/minify/issues/102 |
| 761 |
$tests[] = array( |
| 762 |
'var pb = {};', |
| 763 |
'var pb={}', |
| 764 |
); |
| 765 |
$tests[] = array( |
| 766 |
'pb.Initialize = function(settings) {};', |
| 767 |
'pb.Initialize=function(settings){}', |
| 768 |
); |
| 769 |
|
| 770 |
// https://github.com/matthiasmullie/minify/issues/108 |
| 771 |
$tests[] = array( |
| 772 |
'function isHtmlNamespace(node) { |
| 773 |
var ns; |
| 774 |
return typeof node.namespaceURI == UNDEF || ((ns = node.namespaceURI) === null || ns == "http://www.w3.org/1999/xhtml"); |
| 775 |
}', |
| 776 |
'function isHtmlNamespace(node){var ns;return typeof node.namespaceURI==UNDEF||((ns=node.namespaceURI)===null||ns=="http://www.w3.org/1999/xhtml")}', |
| 777 |
); |
| 778 |
|
| 779 |
// https://github.com/matthiasmullie/minify/issues/115 |
| 780 |
$tests[] = array( |
| 781 |
'if(typeof i[s].token=="string")/keyword|support|storage/.test(i[s].token)&&n.push(i[s].regex);else if(typeof i[s].token=="object")for(var u=0,a=i[s].token.length;u<a;u++)if(/keyword|support|storage/.test(i[s].token[u])){}', |
| 782 |
'if(typeof i[s].token=="string")/keyword|support|storage/.test(i[s].token)&&n.push(i[s].regex);else if(typeof i[s].token=="object")for(var u=0,a=i[s].token.length;u<a;u++)if(/keyword|support|storage/.test(i[s].token[u])){}', |
| 783 |
); |
| 784 |
|
| 785 |
// https://github.com/matthiasmullie/minify/issues/120 |
| 786 |
$tests[] = array( |
| 787 |
'function myFuncName() { |
| 788 |
function otherFuncName() { |
| 789 |
if (condition) { |
| 790 |
a = b / 1; // comment 1 |
| 791 |
} else if (condition) { |
| 792 |
a = c / 2; // comment 2 |
| 793 |
} else if (condition) { |
| 794 |
a = d / 3; // comment 3 |
| 795 |
} else { |
| 796 |
a = 0; |
| 797 |
} |
| 798 |
} |
| 799 |
};', |
| 800 |
'function myFuncName(){function otherFuncName(){if(condition){a=b/1}else if(condition){a=c/2}else if(condition){a=d/3}else{a=0}}}', |
| 801 |
); |
| 802 |
|
| 803 |
// https://github.com/matthiasmullie/minify/issues/128 |
| 804 |
$tests[] = array( |
| 805 |
'angle = (i - 3) * (Math.PI * 2) / 12; // THE ANGLE TO MARK.', |
| 806 |
'angle=(i-3)*(Math.PI*2)/12', |
| 807 |
); |
| 808 |
|
| 809 |
// https://github.com/matthiasmullie/minify/issues/124 |
| 810 |
$tests[] = array( |
| 811 |
'return cond ? document._getElementsByXPath(\'.//*\' + cond, element) : [];', |
| 812 |
'return cond?document._getElementsByXPath(\'.//*\'+cond,element):[]', |
| 813 |
); |
| 814 |
$tests[] = array( |
| 815 |
'Sizzle.selectors = { |
| 816 |
match: { |
| 817 |
PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\(([\'"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/ |
| 818 |
}, |
| 819 |
attrMap: { |
| 820 |
"class": "className" |
| 821 |
} |
| 822 |
}', |
| 823 |
'Sizzle.selectors={match:{PSEUDO:/:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\(([\'"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/},attrMap:{"class":"className"}}', |
| 824 |
); |
| 825 |
|
| 826 |
// https://github.com/matthiasmullie/minify/issues/130 |
| 827 |
$tests[] = array( |
| 828 |
'function func(){} |
| 829 |
func() |
| 830 |
{ alert(\'hey\'); }', |
| 831 |
'function func(){} |
| 832 |
func(){alert(\'hey\')}', |
| 833 |
); |
| 834 |
|
| 835 |
// https://github.com/matthiasmullie/minify/issues/133 |
| 836 |
$tests[] = array( |
| 837 |
'if ( args[\'message\'] instanceof Array ) { args[\'message\'] = args[\'message\'].join( \' \' );}', |
| 838 |
'if(args.message instanceof Array){args.message=args.message.join(\' \')}', |
| 839 |
); |
| 840 |
|
| 841 |
// https://github.com/matthiasmullie/minify/issues/134 |
| 842 |
$tests[] = array( |
| 843 |
'e={true:!0,false:!1}', |
| 844 |
'e={true:!0,false:!1}', |
| 845 |
); |
| 846 |
|
| 847 |
// https://github.com/matthiasmullie/minify/issues/134 |
| 848 |
$tests[] = array( |
| 849 |
'if (\'x\'+a in foo && \'y\'+b[a].z in bar)', |
| 850 |
'if(\'x\'+a in foo&&\'y\'+b[a].z in bar)', |
| 851 |
); |
| 852 |
|
| 853 |
// https://github.com/matthiasmullie/minify/issues/136 |
| 854 |
$tests[] = array( |
| 855 |
'XPRSHelper.isManagable = function(presetId){ if (presetId in XPRSHelper.presetTypes){ return (XPRSHelper.presetTypes[presetId]["GROUP"] in {"FEATURES":true,"SLIDESHOWS":true,"GALLERIES":true}); } return false; };', |
| 856 |
'XPRSHelper.isManagable=function(presetId){if(presetId in XPRSHelper.presetTypes){return(XPRSHelper.presetTypes[presetId].GROUP in{"FEATURES":!0,"SLIDESHOWS":!0,"GALLERIES":!0})}return!1}', |
| 857 |
); |
| 858 |
|
| 859 |
// https://github.com/matthiasmullie/minify/issues/138 |
| 860 |
$tests[] = array( |
| 861 |
'matchers.push(/^[0-9]*$/.source);', |
| 862 |
'matchers.push(/^[0-9]*$/.source)', |
| 863 |
); |
| 864 |
$tests[] = array( |
| 865 |
'matchers.push(/^[0-9]*$/.source); |
| 866 |
String(dateString).match(/^[0-9]*$/);', |
| 867 |
'matchers.push(/^[0-9]*$/.source);String(dateString).match(/^[0-9]*$/)', |
| 868 |
); |
| 869 |
|
| 870 |
// https://github.com/matthiasmullie/minify/issues/139 |
| 871 |
$tests[] = array( |
| 872 |
__DIR__.'/sample/line_endings/lf/script.js', |
| 873 |
'var a=1', |
| 874 |
); |
| 875 |
$tests[] = array( |
| 876 |
__DIR__.'/sample/line_endings/cr/script.js', |
| 877 |
'var a=1', |
| 878 |
); |
| 879 |
$tests[] = array( |
| 880 |
__DIR__.'/sample/line_endings/crlf/script.js', |
| 881 |
'var a=1', |
| 882 |
); |
| 883 |
|
| 884 |
// https://github.com/matthiasmullie/minify/issues/142 |
| 885 |
$tests[] = array( |
| 886 |
'return { |
| 887 |
l: ((116 * y) - 16) / 100, // [0,100] |
| 888 |
a: ((500 * (x - y)) + 128) / 255, // [-128,127] |
| 889 |
b: ((200 * (y - z)) + 128) / 255 // [-128,127] |
| 890 |
};', |
| 891 |
'return{l:((116*y)-16)/100,a:((500*(x-y))+128)/255,b:((200*(y-z))+128)/255}', |
| 892 |
); |
| 893 |
|
| 894 |
// https://github.com/matthiasmullie/minify/issues/143 |
| 895 |
$tests[] = array( |
| 896 |
"if(nutritionalPortionWeightUnit == 'lbs' && blockUnit == 'oz'){ |
| 897 |
itemFat = (qty * (fat/nutritionalPortionWeight))/16; |
| 898 |
itemProtein = (qty * (protein/nutritionalPortionWeight))/16; |
| 899 |
itemCarbs = (qty * (carbs/nutritionalPortionWeight))/16; |
| 900 |
itemKcal = (qty * (kcal/nutritionalPortionWeight))/16; |
| 901 |
}", |
| 902 |
"if(nutritionalPortionWeightUnit=='lbs'&&blockUnit=='oz'){itemFat=(qty*(fat/nutritionalPortionWeight))/16;itemProtein=(qty*(protein/nutritionalPortionWeight))/16;itemCarbs=(qty*(carbs/nutritionalPortionWeight))/16;itemKcal=(qty*(kcal/nutritionalPortionWeight))/16}", |
| 903 |
); |
| 904 |
$tests[] = array( |
| 905 |
'itemFat = (qty * (fat/nutritionalPortionWeight))/16; |
| 906 |
itemFat = (qty * (fat/nutritionalPortionWeight))/(28.3495*16);', |
| 907 |
'itemFat=(qty*(fat/nutritionalPortionWeight))/16;itemFat=(qty*(fat/nutritionalPortionWeight))/(28.3495*16)', |
| 908 |
); |
| 909 |
|
| 910 |
// https://github.com/matthiasmullie/minify/issues/146 |
| 911 |
$tests[] = array( |
| 912 |
'rnoContent = /^(?:GET|HEAD)$/, |
| 913 |
rprotocol = /^\/\//, |
| 914 |
/* ... |
| 915 |
*/ |
| 916 |
prefilters = {};', |
| 917 |
'rnoContent=/^(?:GET|HEAD)$/,rprotocol=/^\/\//,prefilters={}', |
| 918 |
); |
| 919 |
$tests[] = array( |
| 920 |
'elem.getAttribute("type")!==null)+"/"+elem.type |
| 921 |
var rprotocol=/^\/\//,prefilters={}', |
| 922 |
'elem.getAttribute("type")!==null)+"/"+elem.type |
| 923 |
var rprotocol=/^\/\//,prefilters={}', |
| 924 |
); |
| 925 |
$tests[] = array( |
| 926 |
'map: function( elems, callback, arg ) { |
| 927 |
for ( i in elems ) { |
| 928 |
value = callback( elems[ i ], i, arg ); |
| 929 |
if ( value != null ) { |
| 930 |
ret.push( value ); |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
return concat.apply( [], ret ); |
| 935 |
}', |
| 936 |
'map:function(elems,callback,arg){for(i in elems){value=callback(elems[i],i,arg);if(value!=null){ret.push(value)}} |
| 937 |
return concat.apply([],ret)}', |
| 938 |
); |
| 939 |
|
| 940 |
// https://github.com/matthiasmullie/minify/issues/167 |
| 941 |
$tests[] = array( |
| 942 |
'this.valueMap.false', |
| 943 |
'this.valueMap.false', |
| 944 |
); |
| 945 |
$tests[] = array( |
| 946 |
'this.valueMap . false', |
| 947 |
'this.valueMap.false', |
| 948 |
); |
| 949 |
$tests[] = array( |
| 950 |
'false!==true', |
| 951 |
'!1!==!0', |
| 952 |
); |
| 953 |
|
| 954 |
// https://github.com/matthiasmullie/minify/issues/164 |
| 955 |
$tests[] = array( |
| 956 |
'Calendar.createElement = function(type, parent) { |
| 957 |
var el = null; |
| 958 |
if (document.createElementNS) { |
| 959 |
// use the XHTML namespace; IE won\'t normally get here unless |
| 960 |
// _they_ "fix" the DOM2 implementation. |
| 961 |
el = document.createElementNS("http://www.w3.org/1999/xhtml", type); |
| 962 |
} else { |
| 963 |
el = document.createElement(type); |
| 964 |
} |
| 965 |
if (typeof parent != "undefined") { |
| 966 |
parent.appendChild(el); |
| 967 |
} |
| 968 |
return el; |
| 969 |
};', |
| 970 |
'Calendar.createElement=function(type,parent){var el=null;if(document.createElementNS){el=document.createElementNS("http://www.w3.org/1999/xhtml",type)}else{el=document.createElement(type)} |
| 971 |
if(typeof parent!="undefined"){parent.appendChild(el)} |
| 972 |
return el}', |
| 973 |
); |
| 974 |
$tests[] = array( |
| 975 |
"$(this).find('iframe').hide().attr('src', '//about:blank').end().empty();", |
| 976 |
"$(this).find('iframe').hide().attr('src','//about:blank').end().empty()", |
| 977 |
); |
| 978 |
|
| 979 |
// https://github.com/matthiasmullie/minify/issues/163 |
| 980 |
$tests[] = array( |
| 981 |
'q = d / 4 / b.width()', |
| 982 |
'q=d/4/b.width()', |
| 983 |
); |
| 984 |
|
| 985 |
// https://github.com/matthiasmullie/minify/issues/182 |
| 986 |
$tests[] = array( |
| 987 |
'label = input.val().replace(/\\\\/g, \'/\').replace(/.*\//, \'\');', |
| 988 |
'label=input.val().replace(/\\\\/g,\'/\').replace(/.*\//,\'\')', |
| 989 |
); |
| 990 |
|
| 991 |
// https://github.com/matthiasmullie/minify/issues/178 |
| 992 |
$tests[] = array( |
| 993 |
'lunr.SortedSet.prototype.add = function () { |
| 994 |
var i, element |
| 995 |
|
| 996 |
for (i = 0; i < arguments.length; i++) { |
| 997 |
element = arguments[i] |
| 998 |
if (~this.indexOf(element)) continue |
| 999 |
this.elements.splice(this.locationFor(element), 0, element) |
| 1000 |
} |
| 1001 |
|
| 1002 |
this.length = this.elements.length |
| 1003 |
}', |
| 1004 |
'lunr.SortedSet.prototype.add=function(){var i,element |
| 1005 |
for(i=0;i<arguments.length;i++){element=arguments[i] |
| 1006 |
if(~this.indexOf(element))continue |
| 1007 |
this.elements.splice(this.locationFor(element),0,element)} |
| 1008 |
this.length=this.elements.length}', |
| 1009 |
); |
| 1010 |
|
| 1011 |
// https://github.com/matthiasmullie/minify/issues/185 |
| 1012 |
$tests[] = array( |
| 1013 |
'var thisPos = indexOf(stack, this); |
| 1014 |
~thisPos ? stack.splice(thisPos + 1) : stack.push(this) |
| 1015 |
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key) |
| 1016 |
if (~indexOf(stack, value)) value = cycleReplacer.call(this, key, value)', |
| 1017 |
'var thisPos=indexOf(stack,this);~thisPos?stack.splice(thisPos+1):stack.push(this) |
| 1018 |
~thisPos?keys.splice(thisPos,Infinity,key):keys.push(key) |
| 1019 |
if(~indexOf(stack,value))value=cycleReplacer.call(this,key,value)', |
| 1020 |
); |
| 1021 |
|
| 1022 |
// https://github.com/matthiasmullie/minify/issues/186 |
| 1023 |
$tests[] = array( |
| 1024 |
'd/=60;z("/foo/.") |
| 1025 |
/*! This comment should be preserved by the minify process */ |
| 1026 |
|
| 1027 |
var str1 = "//this-text-shoudl-remain-intact"; |
| 1028 |
var str2 = "some other string here";', |
| 1029 |
'd/=60;z("/foo/.") |
| 1030 |
/*! This comment should be preserved by the minify process */ |
| 1031 |
var str1="//this-text-shoudl-remain-intact";var str2="some other string here"', |
| 1032 |
); |
| 1033 |
|
| 1034 |
// https://github.com/matthiasmullie/minify/issues/189 |
| 1035 |
$tests[] = array( |
| 1036 |
'(function() { |
| 1037 |
window.Selector = Class.create({ |
| 1038 |
initialize: function(expression) { |
| 1039 |
this.expression = expression.strip(); |
| 1040 |
}, |
| 1041 |
|
| 1042 |
findElements: function(rootElement) { |
| 1043 |
return Prototype.Selector.select(this.expression, rootElement); |
| 1044 |
}, |
| 1045 |
|
| 1046 |
match: function(element) { |
| 1047 |
return Prototype.Selector.match(element, this.expression); |
| 1048 |
}, |
| 1049 |
|
| 1050 |
toString: function() { |
| 1051 |
return this.expression; |
| 1052 |
}, |
| 1053 |
|
| 1054 |
inspect: function() { |
| 1055 |
return "#<Selector: " + this.expression + ">"; |
| 1056 |
} |
| 1057 |
}); |
| 1058 |
|
| 1059 |
Object.extend(Selector, { |
| 1060 |
matchElements: function(elements, expression) { |
| 1061 |
var match = Prototype.Selector.match, |
| 1062 |
results = []; |
| 1063 |
|
| 1064 |
for (var i = 0, length = elements.length; i < length; i++) { |
| 1065 |
var element = elements[i]; |
| 1066 |
if (match(element, expression)) { |
| 1067 |
results.push(Element.extend(element)); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
return results; |
| 1071 |
}, |
| 1072 |
|
| 1073 |
findElement: function(elements, expression, index) { |
| 1074 |
index = index || 0; |
| 1075 |
var matchIndex = 0, element; |
| 1076 |
for (var i = 0, length = elements.length; i < length; i++) { |
| 1077 |
element = elements[i]; |
| 1078 |
if (Prototype.Selector.match(element, expression) && index === matchIndex++) { |
| 1079 |
return Element.extend(element); |
| 1080 |
} |
| 1081 |
} |
| 1082 |
}, |
| 1083 |
|
| 1084 |
findChildElements: function(element, expressions) { |
| 1085 |
var selector = expressions.toArray().join(\', \'); |
| 1086 |
return Prototype.Selector.select(selector, element || document); |
| 1087 |
} |
| 1088 |
}); |
| 1089 |
})(); |
| 1090 |
|
| 1091 |
function someOtherFunction() { |
| 1092 |
}', |
| 1093 |
'(function(){window.Selector=Class.create({initialize:function(expression){this.expression=expression.strip()},findElements:function(rootElement){return Prototype.Selector.select(this.expression,rootElement)},match:function(element){return Prototype.Selector.match(element,this.expression)},toString:function(){return this.expression},inspect:function(){return"#<Selector: "+this.expression+">"}});Object.extend(Selector,{matchElements:function(elements,expression){var match=Prototype.Selector.match,results=[];for(var i=0,length=elements.length;i<length;i++){var element=elements[i];if(match(element,expression)){results.push(Element.extend(element))}} |
| 1094 |
return results},findElement:function(elements,expression,index){index=index||0;var matchIndex=0,element;for(var i=0,length=elements.length;i<length;i++){element=elements[i];if(Prototype.Selector.match(element,expression)&&index===matchIndex++){return Element.extend(element)}}},findChildElements:function(element,expressions){var selector=expressions.toArray().join(\', \');return Prototype.Selector.select(selector,element||document)}})})();function someOtherFunction(){}', |
| 1095 |
); |
| 1096 |
|
| 1097 |
// https://github.com/matthiasmullie/minify/issues/190 |
| 1098 |
$tests[] = array( |
| 1099 |
'function fullwidth_portfolio_carousel_slide( $arrow ) { |
| 1100 |
var $the_portfolio = $arrow.parents(\'.et_pb_fullwidth_portfolio\'), |
| 1101 |
$portfolio_items = $the_portfolio.find(\'.et_pb_portfolio_items\'), |
| 1102 |
$the_portfolio_items = $portfolio_items.find(\'.et_pb_portfolio_item\'), |
| 1103 |
$active_carousel_group = $portfolio_items.find(\'.et_pb_carousel_group.active\'), |
| 1104 |
slide_duration = 700, |
| 1105 |
items = $portfolio_items.data(\'items\'), |
| 1106 |
columns = $portfolio_items.data(\'portfolio-columns\'), |
| 1107 |
item_width = $active_carousel_group.innerWidth() / columns, //$active_carousel_group.children().first().innerWidth(), |
| 1108 |
original_item_width = ( 100 / columns ) + \'%\'; |
| 1109 |
|
| 1110 |
if ( \'undefined\' == typeof items ) { |
| 1111 |
return; |
| 1112 |
} |
| 1113 |
|
| 1114 |
if ( $the_portfolio.data(\'carouseling\') ) { |
| 1115 |
return; |
| 1116 |
} |
| 1117 |
|
| 1118 |
$the_portfolio.data(\'carouseling\', true); |
| 1119 |
|
| 1120 |
$active_carousel_group.children().each(function(){ |
| 1121 |
$(this).css({\'width\': $(this).innerWidth() + 1, \'position\':\'absolute\', \'left\': ( $(this).innerWidth() * ( $(this).data(\'position\') - 1 ) ) }); |
| 1122 |
}); |
| 1123 |
}', |
| 1124 |
'function fullwidth_portfolio_carousel_slide($arrow){var $the_portfolio=$arrow.parents(\'.et_pb_fullwidth_portfolio\'),$portfolio_items=$the_portfolio.find(\'.et_pb_portfolio_items\'),$the_portfolio_items=$portfolio_items.find(\'.et_pb_portfolio_item\'),$active_carousel_group=$portfolio_items.find(\'.et_pb_carousel_group.active\'),slide_duration=700,items=$portfolio_items.data(\'items\'),columns=$portfolio_items.data(\'portfolio-columns\'),item_width=$active_carousel_group.innerWidth()/columns,original_item_width=(100/columns)+\'%\';if(\'undefined\'==typeof items){return} |
| 1125 |
if($the_portfolio.data(\'carouseling\')){return} |
| 1126 |
$the_portfolio.data(\'carouseling\',!0);$active_carousel_group.children().each(function(){$(this).css({\'width\':$(this).innerWidth()+1,\'position\':\'absolute\',\'left\':($(this).innerWidth()*($(this).data(\'position\')-1))})})}', |
| 1127 |
); |
| 1128 |
|
| 1129 |
$tests[] = array( |
| 1130 |
'if("some string" /*or comment*/)/regex/', |
| 1131 |
'if("some string")/regex/', |
| 1132 |
); |
| 1133 |
|
| 1134 |
// https://github.com/matthiasmullie/minify/issues/195 |
| 1135 |
$tests[] = array( |
| 1136 |
'"function"!=typeof/./&&"object"!=typeof Int8Array', |
| 1137 |
'"function"!=typeof/./&&"object"!=typeof Int8Array', |
| 1138 |
); |
| 1139 |
$tests[] = array( |
| 1140 |
'if (true || /^(https?:)?\/\//.test(\'xxx\')) alert(1);', |
| 1141 |
'if(!0||/^(https?:)?\/\//.test(\'xxx\'))alert(1)', |
| 1142 |
); |
| 1143 |
|
| 1144 |
// https://github.com/matthiasmullie/minify/issues/196 |
| 1145 |
$tests[] = array( |
| 1146 |
'if ( true ) { |
| 1147 |
console.log(true); |
| 1148 |
// ...comment number 2 (something with dots?) |
| 1149 |
} else { |
| 1150 |
console.log(false); |
| 1151 |
}', |
| 1152 |
'if(!0){console.log(!0)}else{console.log(!1)}', |
| 1153 |
); |
| 1154 |
|
| 1155 |
// https://github.com/matthiasmullie/minify/issues/197 |
| 1156 |
$tests[] = array( |
| 1157 |
'if(!e.allow_html_data_urls&&V.test(k)&&!/^data:image\//i.test(k))return', |
| 1158 |
'if(!e.allow_html_data_urls&&V.test(k)&&!/^data:image\//i.test(k))return', |
| 1159 |
); |
| 1160 |
|
| 1161 |
// https://github.com/matthiasmullie/minify/issues/199 |
| 1162 |
$tests[] = array( |
| 1163 |
'// This case was fixed on version 1.3.50 |
| 1164 |
// function () { |
| 1165 |
// return false; |
| 1166 |
// }; |
| 1167 |
|
| 1168 |
// Next two cases failed since version 1.3.49 |
| 1169 |
// function () { |
| 1170 |
// return false; //.click(); |
| 1171 |
// }; |
| 1172 |
|
| 1173 |
// function () { |
| 1174 |
// ;//; |
| 1175 |
// }', |
| 1176 |
'', |
| 1177 |
); |
| 1178 |
|
| 1179 |
// https://github.com/matthiasmullie/minify/issues/204 |
| 1180 |
$tests[] = array( |
| 1181 |
'data = data.replace(this.video.reUrlYoutube, iframeStart + \'//www.youtube.com/embed/$1\' + iframeEnd);', |
| 1182 |
'data=data.replace(this.video.reUrlYoutube,iframeStart+\'//www.youtube.com/embed/$1\'+iframeEnd)' |
| 1183 |
); |
| 1184 |
$tests[] = array( |
| 1185 |
'pattern = /(\/)\'/; |
| 1186 |
a = \'b\';', |
| 1187 |
'pattern=/(\/)\'/;a=\'b\'', |
| 1188 |
); |
| 1189 |
|
| 1190 |
// https://github.com/matthiasmullie/minify/issues/205 |
| 1191 |
$tests[] = array( |
| 1192 |
'return { lineComment: parserConfig.slashComments ? "//" : null }', |
| 1193 |
'return{lineComment:parserConfig.slashComments?"//":null}', |
| 1194 |
); |
| 1195 |
$tests[] = array( |
| 1196 |
'\'//\'.match(/\/|\'/);', |
| 1197 |
'\'//\'.match(/\/|\'/)', |
| 1198 |
); |
| 1199 |
|
| 1200 |
// https://github.com/matthiasmullie/minify/issues/209 |
| 1201 |
$tests[] = array( |
| 1202 |
'var my_regexes = [/[a-z]{3}\//g, \'a string\', 1];', |
| 1203 |
'var my_regexes=[/[a-z]{3}\//g,\'a string\',1]', |
| 1204 |
); |
| 1205 |
|
| 1206 |
// https://github.com/matthiasmullie/minify/issues/211 |
| 1207 |
$tests[] = array( |
| 1208 |
'if (last){ |
| 1209 |
for(i=1;i<3;i++); |
| 1210 |
} else if (first){ |
| 1211 |
for(i in list); |
| 1212 |
} else { |
| 1213 |
while(this.rm(name, check, false)); |
| 1214 |
}', |
| 1215 |
'if(last){for(i=1;i<3;i++);}else if(first){for(i in list);}else{while(this.rm(name,check,!1));}', |
| 1216 |
); |
| 1217 |
$tests[] = array( |
| 1218 |
'if(0){do{}while(1)}', |
| 1219 |
'if(0){do{}while(1)}', |
| 1220 |
); |
| 1221 |
$tests[] = array( |
| 1222 |
'if(0){do{}while(1);}', |
| 1223 |
'if(0){do{}while(1);}', |
| 1224 |
); |
| 1225 |
|
| 1226 |
// https://github.com/matthiasmullie/minify/issues/214 |
| 1227 |
$tests[] = array( |
| 1228 |
'/\/|\'/; |
| 1229 |
\'.ctd_panel_content .ctd_preview\';', |
| 1230 |
'/\/|\'/;\'.ctd_panel_content .ctd_preview\'', |
| 1231 |
); |
| 1232 |
|
| 1233 |
// https://github.com/matthiasmullie/minify/issues/218 |
| 1234 |
$tests[] = array( |
| 1235 |
"inside: { |
| 1236 |
'rule': /@[\w-]+/ |
| 1237 |
// See rest below |
| 1238 |
}", |
| 1239 |
"inside:{'rule':/@[\w-]+/}", |
| 1240 |
); |
| 1241 |
$tests[] = array( |
| 1242 |
"inside: { |
| 1243 |
'rule': /@[\w-]+/ // See rest below |
| 1244 |
}", |
| 1245 |
"inside:{'rule':/@[\w-]+/}", |
| 1246 |
); |
| 1247 |
$tests[] = array( |
| 1248 |
"inside: { |
| 1249 |
'rule': /@[\w-]+/// See rest below |
| 1250 |
}", |
| 1251 |
"inside:{'rule':/@[\w-]+/}", |
| 1252 |
); |
| 1253 |
$tests[] = array( |
| 1254 |
"(1 + 2) / 3 / 4", |
| 1255 |
"(1+2)/3/4", |
| 1256 |
); |
| 1257 |
|
| 1258 |
// https://github.com/matthiasmullie/minify/issues/221 |
| 1259 |
$tests[] = array( |
| 1260 |
'$export.F*/Version\/10\.\d+(\.\d+)? Safari\//.test(userAgent)', |
| 1261 |
'$export.F*/Version\/10\.\d+(\.\d+)? Safari\//.test(userAgent)', |
| 1262 |
); |
| 1263 |
$tests[] = array( |
| 1264 |
'new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)', |
| 1265 |
'new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)', |
| 1266 |
); |
| 1267 |
|
| 1268 |
// https://github.com/matthiasmullie/minify/issues/227 |
| 1269 |
$tests[] = array( |
| 1270 |
__DIR__.'/sample/bugs/227/original.js', |
| 1271 |
file_get_contents(__DIR__.'/sample/bugs/227/minified.js'), |
| 1272 |
); |
| 1273 |
|
| 1274 |
// https://github.com/matthiasmullie/minify/issues/229 |
| 1275 |
$tests[] = array( |
| 1276 |
__DIR__.'/sample/bugs/229/original.js', |
| 1277 |
file_get_contents(__DIR__.'/sample/bugs/229/minified.js'), |
| 1278 |
); |
| 1279 |
|
| 1280 |
// https://github.com/matthiasmullie/minify/issues/231 |
| 1281 |
$tests[] = array( |
| 1282 |
'var x = (2 + 2) / 2; /// =2', |
| 1283 |
'var x=(2+2)/2', |
| 1284 |
); |
| 1285 |
$tests[] = array( |
| 1286 |
'if(1)/real + regex/.test("real regex")', |
| 1287 |
'if(1)/real + regex/.test("real regex")', |
| 1288 |
); |
| 1289 |
|
| 1290 |
// https://github.com/matthiasmullie/minify/issues/234 |
| 1291 |
$tests[] = array( |
| 1292 |
'if ( !item.hasClass(\'megamenu\') && (menuPositionX + subMenuWidth) > ( windowWidth - containerWidth )/2 + containerWidth) { |
| 1293 |
subMenu.addClass(\'eut-position-right\'); |
| 1294 |
} |
| 1295 |
|
| 1296 |
////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1297 |
// GLOBAL VARIABLES |
| 1298 |
////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1299 |
var largeScreen = 2048;', |
| 1300 |
'if(!item.hasClass(\'megamenu\')&&(menuPositionX+subMenuWidth)>(windowWidth-containerWidth)/2+containerWidth){subMenu.addClass(\'eut-position-right\')} |
| 1301 |
var largeScreen=2048', |
| 1302 |
); |
| 1303 |
|
| 1304 |
// https://github.com/matthiasmullie/minify/issues/242 |
| 1305 |
$tests[] = array( |
| 1306 |
'/^\[(x| )\](?=\s)/i // Must follow listRE', |
| 1307 |
'/^\[(x| )\](?=\s)/i', |
| 1308 |
); |
| 1309 |
|
| 1310 |
// known minified files to help doublecheck changes in places not yet |
| 1311 |
// anticipated in these tests |
| 1312 |
$files = glob(__DIR__.'/sample/minified/*.js'); |
| 1313 |
foreach ($files as $file) { |
| 1314 |
$content = trim(file_get_contents($file)); |
| 1315 |
$tests[] = array($content, $content); |
| 1316 |
} |
| 1317 |
// update tests' expected results for cross-system compatibility |
| 1318 |
foreach ($tests as &$test) { |
| 1319 |
if (!empty($test[1])) { |
| 1320 |
$test[1] = str_replace("\r", '', $test[1]); |
| 1321 |
} |
| 1322 |
} |
| 1323 |
|
| 1324 |
return $tests; |
| 1325 |
} |
| 1326 |
} |
| 1327 |
|