1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-21 13:21:59 +02:00

Fixes #53 (github) handles division following line break

This commit is contained in:
Steve Clay
2013-04-01 11:25:27 -04:00
parent d67feea182
commit 6f5721d2db
9 changed files with 30 additions and 16 deletions

View File

@@ -268,11 +268,11 @@ class JSMin {
*/ */
protected function isRegexpLiteral() protected function isRegexpLiteral()
{ {
if (false !== strpos("(,=:[!&|?+-~*\n{", $this->a)) { if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
// we obviously aren't dividing // we obviously aren't dividing
return true; return true;
} }
if (' ' === $this->a) { if ($this->a === ' ' || $this->a === "\n") {
$length = strlen($this->output); $length = strlen($this->output);
if ($length < 2) { // weird edge case if ($length < 2) { // weird edge case
return true; return true;

View File

@@ -1,5 +1,3 @@
!function(){}(window) !function(){}(window)
!function(){}(window) !function(){}(window)
x = / [/] /;

View File

@@ -1,3 +1,2 @@
!function(){}(window) !function(){}(window)
!function(){}(window) !function(){}(window)
x=/ [/] /;

View File

@@ -1,4 +0,0 @@
function testIssue74() {
return /'/;
}

View File

@@ -1 +0,0 @@
function testIssue74(){return /'/;}

View File

@@ -1 +0,0 @@
function testIssue74(){return /'/}

View File

@@ -0,0 +1,20 @@
function testIssue74() {
return /'/;
}
!function(s) {
return /^[£$€?.]/.test(s);
}();
typeof
/ ' /;
x = / [/] /;
1
/ foo;
(2)
/ foo;

View File

@@ -0,0 +1,3 @@
function testIssue74(){return /'/;}
!function(s){return /^[£$€?.]/.test(s);}();typeof
/ ' /;x=/ [/] /;1/foo;(2)/foo;

View File

@@ -47,10 +47,10 @@ function test_JSMin()
} }
} }
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js'); $src = file_get_contents($thisDir . '/_test_files/js/regexes.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js'); $minExpected = file_get_contents($thisDir . '/_test_files/js/regexes.min.js');
$minOutput = JSMin::minify($src); $minOutput = JSMin::minify($src);
assertTrue($minExpected == $minOutput, 'JSMin : Quotes in RegExp literals (Issue 74)'); assertTrue($minExpected == $minOutput, 'JSMin : Identify RegExp literals');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n"; echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n"; echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";