You are here

private function JSParser::reduce in Javascript Aggregator 6

1 call to JSParser::reduce()
JSParser::Expression in ./jsminplus.php

File

./jsminplus.php, line 1586

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]
  $te = $this->t
    ->currentToken()->end;
  if ($n->end < $te) {
    $n->end = $te;
  }
  array_push($operands, $n);
  return $n;
}