Same name in other branches
  1. 5.0.x advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
  2. 6.0.x advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
  3. 7.x-1.x advagg_js_compress/jspacker.inc \JavaScriptPacker::_basicCompression()
  4. 7.x-2.x advagg_js_compress/jspacker.inc \JavaScriptPacker::_basicCompression()
  5. 8.x-2.x advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
  6. 8.x-4.x advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()

File

advagg_js_minify/jspacker.inc, line 140

Class

JavaScriptPacker

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);
}