You are here

protected function Minifier::loop in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.2 advagg_js_minify/jshrink.inc \JShrink\Minifier::loop()
  2. 8.3 advagg_js_minify/jshrink.inc \JShrink\Minifier::loop()
  3. 7.2 advagg_js_compress/jshrink.inc \JShrink\Minifier::loop()

The primary action occurs here. This function loops through the input string, outputting anything that's relevant and discarding anything that is not.

1 call to Minifier::loop()
Minifier::minifyDirectToOutput in advagg_js_minify/jshrink.inc
Processes a javascript string and outputs only the required characters, stripping out all unneeded characters.

File

advagg_js_minify/jshrink.inc, line 218

Class

Minifier
Minifier

Namespace

JShrink

Code

protected function loop() {
  while ($this->a !== false && !is_null($this->a) && $this->a !== '') {
    switch ($this->a) {

      // new lines
      case "\n":

        // if the next line is something that can't stand alone preserve the newline
        if ($this->b !== false && strpos('(-+{[@', $this->b) !== false) {
          echo $this->a;
          $this
            ->saveString();
          break;
        }

        // if B is a space we skip the rest of the switch block and go down to the
        // string/regex check below, resetting $this->b with getReal
        if ($this->b === ' ') {
          break;
        }

      // otherwise we treat the newline like a space
      case ' ':
        if (static::isAlphaNumeric($this->b)) {
          echo $this->a;
        }
        $this
          ->saveString();
        break;
      default:
        switch ($this->b) {
          case "\n":
            if (strpos('}])+-"\'', $this->a) !== false) {
              echo $this->a;
              $this
                ->saveString();
              break;
            }
            else {
              if (static::isAlphaNumeric($this->a)) {
                echo $this->a;
                $this
                  ->saveString();
              }
            }
            break;
          case ' ':
            if (!static::isAlphaNumeric($this->a)) {
              break;
            }
          default:

            // check for some regex that breaks stuff
            if ($this->a === '/' && ($this->b === '\'' || $this->b === '"')) {
              $this
                ->saveRegex();
              continue 3;
            }
            echo $this->a;
            $this
              ->saveString();
            break;
        }
    }

    // do reg check of doom
    $this->b = $this
      ->getReal();
    if ($this->b == '/' && strpos('(,=:[!&|?', $this->a) !== false) {
      $this
        ->saveRegex();
    }
  }
}