Skip to content

Commit

Permalink
Merge pull request #266 from owncloud/update_jsqueeze
Browse files Browse the repository at this point in the history
update JSqueeze to version 2.0.4
  • Loading branch information
DeepDiver1975 committed Apr 12, 2016
2 parents 631b7de + 6accc31 commit 182a104
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 90 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion composer/LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (c) 2016 Nils Adermann, Jordi Boggiano
Copyright (c) 2015 Nils Adermann, Jordi Boggiano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'Sabre\\CalDAV\\' => array($vendorDir . '/sabre/dav/lib/CalDAV'),
'React\\Promise\\' => array($vendorDir . '/react/promise/src'),
'Punic\\' => array($vendorDir . '/punic/punic/code'),
'Patchwork\\' => array($vendorDir . '/patchwork/jsqueeze/src', $vendorDir . '/patchwork/utf8/src/Patchwork'),
'Patchwork\\' => array($vendorDir . '/patchwork/utf8/src/Patchwork', $vendorDir . '/patchwork/jsqueeze/src'),
'League\\Flysystem\\' => array($vendorDir . '/league/flysystem/src'),
'InterfaSys\\LogNormalizer\\' => array($vendorDir . '/interfasys/lognormalizer/src'),
'Icewind\\Streams\\Tests\\' => array($vendorDir . '/icewind/streams/tests'),
Expand Down
98 changes: 49 additions & 49 deletions composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,55 +675,6 @@
"parser"
]
},
{
"name": "patchwork/jsqueeze",
"version": "v2.0.3",
"version_normalized": "2.0.3.0",
"source": {
"type": "git",
"url": "https://github.com/tchwork/jsqueeze.git",
"reference": "074a7ac403d1fae262fd662c43c04b62d71c3e50"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tchwork/jsqueeze/zipball/074a7ac403d1fae262fd662c43c04b62d71c3e50",
"reference": "074a7ac403d1fae262fd662c43c04b62d71c3e50",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2015-08-20 11:07:02",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Patchwork\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"(Apache-2.0 or GPL-2.0)"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
}
],
"description": "Efficient JavaScript minification in PHP",
"homepage": "https://github.com/tchwork/jsqueeze",
"keywords": [
"compression",
"javascript",
"minification"
]
},
{
"name": "ircmaxell/password-compat",
"version": "v1.0.4",
Expand Down Expand Up @@ -3142,5 +3093,54 @@
"framework",
"iCalendar"
]
},
{
"name": "patchwork/jsqueeze",
"version": "v2.0.4",
"version_normalized": "2.0.4.0",
"source": {
"type": "git",
"url": "https://github.com/tchwork/jsqueeze.git",
"reference": "74203bf6f4f891f5741cf286c2e47ece120f8b3e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tchwork/jsqueeze/zipball/74203bf6f4f891f5741cf286c2e47ece120f8b3e",
"reference": "74203bf6f4f891f5741cf286c2e47ece120f8b3e",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-03-27 16:56:41",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Patchwork\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"(Apache-2.0 or GPL-2.0)"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
}
],
"description": "Efficient JavaScript minification in PHP",
"homepage": "https://github.com/tchwork/jsqueeze",
"keywords": [
"compression",
"javascript",
"minification"
]
}
]
92 changes: 58 additions & 34 deletions patchwork/jsqueeze/src/JSqueeze.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php // vi: set fenc=utf-8 ts=4 sw=4 et:
/*
* Copyright (C) 2015 Nicolas Grekas - p@tchwork.com
* Copyright (C) 2016 Nicolas Grekas - p@tchwork.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the (at your option):
Expand Down Expand Up @@ -79,14 +79,18 @@ class JSqueeze

$varRx = '(?:[a-zA-Z_$])[a-zA-Z0-9_$]*',
$reserved = array(
'abstract','as','boolean','break','byte','case','catch','char','class',
'const','continue','debugger','default','delete','do','double','else',
'enum','export','extends','false','final','finally','float','for',
'function','goto','if','implements','import','in','instanceof','int',
'long','native','new','null','package','private','protected','public',
'return','short','static','super','switch','synchronized','this',
'throw','throws','transient','true','try','typeof','var','void',
'while','with','yield','let','interface',
// Literals
'true','false','null',
// ES6
'break','case','class','catch','const','continue','debugger','default','delete','do','else','export','extends','finally','for','function','if','import','in','instanceof','new','return','super','switch','this','throw','try','typeof','var','void','while','with','yield',
// Future
'enum',
// Strict mode
'implements','package','protected','static','let','interface','private','public',
// Module
'await',
// Older standards
'abstract','boolean','byte','char','double','final','float','goto','int','long','native','short','synchronized','throws','transient','volatile',
);


Expand Down Expand Up @@ -310,14 +314,31 @@ protected function extractStrings($f)
}
else
{
$a = $j && ' ' == $code[$j] ? $code[$j-1] : $code[$j];
if (false !== strpos('-!%&;<=>~:^+|,(*?[{ ', $a)
$a = $j && (' ' == $code[$j] || "\x7F" == $code[$j]) ? $code[$j-1] : $code[$j];
if (false !== strpos('-!%&;<=>~:^+|,()*?[{} ', $a)
|| (false !== strpos('oenfd', $a)
&& preg_match(
"'(?<![\$.a-zA-Z0-9_])(do|else|return|typeof|yield) ?$'",
"'(?<![\$.a-zA-Z0-9_])(do|else|return|typeof|yield[ \x7F]?\*?)[ \x7F]?$'",
substr($code, $j-7, 8)
)))
{
if (')' === $a && $j > 1)
{
$a = 1;
$k = $j - (' ' == $code[$j] || "\x7F" == $code[$j]) - 1;
while ($k >= 0 && $a)
{
if ('(' === $code[$k]) --$a;
else if (')' === $code[$k]) ++$a;
--$k;
}
if (!preg_match("'(?<![\$.a-zA-Z0-9_])(if|for|while)[ \x7F]?$'", substr($code, 0, $k+1)))
{
$code[++$j] = '/';
break;
}
}

$key = "//''\"\"" . $K++ . $instr = "/'";
$a = $j;
$code .= $key;
Expand Down Expand Up @@ -346,24 +367,24 @@ protected function extractStrings($f)
break;

case "\n":
if ($j > 5)
if ($j > 3)
{
' ' == $code[$j] && --$j;
if (' ' == $code[$j] || "\x7F" == $code[$j]) --$j;

$code[++$j] =
false !== strpos('kend', $code[$j-1])
false !== strpos('kend+-', $code[$j-1])
&& preg_match(
"'(?<![\$.a-zA-Z0-9_])(break|continue|return|yield) ?$'",
"'(?:\+\+|--|(?<![\$.a-zA-Z0-9_])(break|continue|return|yield[ \x7F]?\*?))[ \x7F]?$'",
substr($code, $j-8, 9)
)
? ';' : ' ';
? ';' : "\x7F";

break;
}

case "\t": $f[$i] = ' ';
case ' ':
if (!$j || ' ' == $code[$j]) break;
if (!$j || ' ' == $code[$j] || "\x7F" == $code[$j]) break;

default:
$code[++$j] = $f[$i];
Expand All @@ -377,11 +398,15 @@ protected function extractStrings($f)
$cc_on && $this->restoreCc($code, false);

// Protect wanted spaces and remove unwanted ones
$code = strtr($code, "\x7F", ' ');
$code = str_replace('- -', "-\x7F-", $code);
$code = str_replace('+ +', "+\x7F+", $code);
$code = str_replace('get ', "get\x7F", $code);
$code = str_replace('set ', "set\x7F", $code);
$code = preg_replace("'(\d)\s+\.\s*([a-zA-Z\$_[(])'", "$1\x7F.$2", $code);
$code = preg_replace("# ([-!%&;<=>~:.^+|,()*?[\]{}/']+)#", '$1', $code);
$code = preg_replace( "#([-!%&;<=>~:.^+|,()*?[\]{}/]+) #", '$1', $code);
$cc_on && $code = preg_replace_callback("'//[^\'].*?@#3'", function ($m) {return strtr($m[0], ' ', "\x7F");}, $code);

// Replace new Array/Object by []/{}
false !== strpos($code, 'new Array' ) && $code = preg_replace( "'new Array(?:\(\)|([;\])},:]))'", '[]$1', $code);
Expand Down Expand Up @@ -470,19 +495,19 @@ protected function extractStrings($f)
}

$f = implode('', $f);
$cc_on && $f = str_replace('@#3', "\n", $f);
$cc_on && $f = str_replace('@#3', "\r", $f);

// Fix "else ;" empty instructions
$f = preg_replace("'(?<![\$.a-zA-Z0-9_])else\n'", "\n", $f);

$r1 = array( // keywords with a direct object
'case','delete','do','else','function','in','instanceof','break',
'case','delete','do','else','function','in','instanceof','of','break',
'new','return','throw','typeof','var','void','yield','let','if',
'const',
);

$r2 = array( // keywords with a subject
'in','instanceof',
'in','instanceof','of',
);

// Fix missing semi-colons
Expand Down Expand Up @@ -879,7 +904,18 @@ protected function renameVars(&$tree, $root)
$this->used_tree =& $tree['used'];

$tree['code'] = preg_replace_callback("#[.,{ ]?(?<![a-zA-Z0-9_\$@]){$this->varRx}:?#", array(&$this, 'getNewName'), $tree['code']);
$this->specialVarRx && $tree['code'] = preg_replace_callback("#//''\"\"[0-9]+'#", array(&$this, 'renameInString'), $tree['code']);

if ($this->specialVarRx && preg_match_all("#//''\"\"[0-9]+'#", $tree['code'], $b))
{
foreach ($b[0] as $a)
{
$this->strings[$a] = preg_replace_callback(
"#[.,{]?(?<![a-zA-Z0-9_\$@]){$this->specialVarRx}:?#",
array(&$this, 'getNewName'),
$this->strings[$a]
);
}
}

foreach ($tree['childs'] as $a => &$b)
{
Expand All @@ -889,18 +925,6 @@ protected function renameVars(&$tree, $root)
}
}

protected function renameInString($a)
{
$b =& $this->strings[$a[0]];
unset($this->strings[$a[0]]);

return preg_replace_callback(
"#[.,{]?(?<![a-zA-Z0-9_\$@]){$this->specialVarRx}:?#",
array(&$this, 'getNewName'),
$b
);
}

protected function getNewName($m)
{
$m = $m[0];
Expand Down

0 comments on commit 182a104

Please sign in to comment.