Same name in other branches
  1. 6.0.x advagg_js_minify/jshrink.inc \JShrink\Minifier::loop()
  2. 7.x-2.x advagg_js_compress/jshrink.inc \JShrink\Minifier::loop()
  3. 8.x-2.x advagg_js_minify/jshrink.inc \JShrink\Minifier::loop()
  4. 8.x-3.x advagg_js_minify/jshrink.inc \JShrink\Minifier::loop()
  5. 8.x-4.x advagg_js_minify/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 dans advagg_js_minify/jshrink.inc
Processes a javascript string and outputs only the required characters, stripping out all unneeded characters.

Fichier

advagg_js_minify/jshrink.inc, line 218

Classe

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