You are here

private function JSParser::reduce in Advanced CSS/JS Aggregation 7.2

Same name and namespace in other branches
  1. 8.4 advagg_js_minify/jsminplus.inc \JSParser::reduce()
  2. 8.2 advagg_js_minify/jsminplus.inc \JSParser::reduce()
  3. 8.3 advagg_js_minify/jsminplus.inc \JSParser::reduce()
  4. 6 advagg_js_compress/jsminplus.inc \JSParser::reduce()
  5. 7 advagg_js_compress/jsminplus.inc \JSParser::reduce()
1 call to JSParser::reduce()
JSParser::Expression in advagg_js_compress/jsminplus.inc

File

advagg_js_compress/jsminplus.inc, line 1743
JSMinPlus version 1.4

Class

JSParser

Code

private function reduce(&$operators, &$operands) {
  $n = array_pop($operators);
  $op = $n->type;
  $arity = $this->opArity[$op];
  $c = count($operands);
  if ($arity == -2) {

    // Flatten left-associative trees
    if ($c >= 2) {
      $left = $operands[$c - 2];
      if ($left->type == $op) {
        $right = array_pop($operands);
        $left
          ->addNode($right);
        return $left;
      }
    }
    $arity = 2;
  }

  // Always use push to add operands to n, to update start and end
  $a = array_splice($operands, $c - $arity);
  for ($i = 0; $i < $arity; $i++) {
    $n
      ->addNode($a[$i]);
  }

  // Include closing bracket or postfix operator in [start,end]
  $token_end = $this->t
    ->currentToken()->end;
  if ($n->end < $token_end) {
    $n->end = $token_end;
  }
  array_push($operands, $n);
  return $n;
}