You are here

private function JavaScriptPacker::_basicCompression in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 8.4 advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
  2. 8.2 advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
  3. 8.3 advagg_js_minify/jspacker.inc \JavaScriptPacker::_basicCompression()
  4. 6 advagg_js_compress/jspacker.inc \JavaScriptPacker::_basicCompression()
  5. 7.2 advagg_js_compress/jspacker.inc \JavaScriptPacker::_basicCompression()

File

advagg_js_compress/jspacker.inc, line 124

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