private function JavaScriptPacker::_basicCompression in Advanced CSS/JS Aggregation 7
Same name and namespace in other branches
- 8.4 advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
- 8.2 advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
- 8.3 advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
- 6 advagg_js_compress/jspacker.inc \JavaScriptPacker::_basicCompression()
- 7.2 advagg_js_compress/jspacker.inc \JavaScriptPacker::_basicCompression()
File
- advagg_js_compress/
jspacker.inc, line 124
Class
Code
private function _basicCompression($script) {
$parser = new ParseMaster();
// make safe
$parser->escapeChar = '\\';
// protect strings
$parser
->add('/\'[^\'\\n\\r]*\'/', self::IGNORE);
$parser
->add('/"[^"\\n\\r]*"/', self::IGNORE);
// remove comments
$parser
->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' ');
$parser
->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' ');
// protect regular expressions
$parser
->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2');
// IGNORE
$parser
->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', self::IGNORE);
// remove: ;;; doSomething();
if ($this->_specialChars) {
$parser
->add('/;;;[^\\n\\r]+[\\n\\r]/');
}
// remove redundant semi-colons
$parser
->add('/\\(;;\\)/', self::IGNORE);
// protect for (;;) loops
$parser
->add('/;+\\s*([};])/', '$2');
// apply the above
$script = $parser
->exec($script);
// remove white-space
$parser
->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3');
$parser
->add('/([+\\-])\\s+([+\\-])/', '$2 $3');
$parser
->add('/\\s+/', '');
// done
return $parser
->exec($script);
}