You are here

private function JSParser::FunctionDefinition in Advanced CSS/JS Aggregation 6

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

File

advagg_js_compress/jsminplus.inc, line 1217

Class

JSParser

Code

private function FunctionDefinition($x, $requireName, $functionForm) {
  $f = new JSNode($this->t);
  if ($f->type != KEYWORD_FUNCTION) {
    $f->type = $f->value == 'get' ? JS_GETTER : JS_SETTER;
  }
  if ($this->t
    ->match(TOKEN_IDENTIFIER)) {
    $f->name = $this->t
      ->currentToken()->value;
  }
  elseif ($requireName) {
    throw $this->t
      ->newSyntaxError('Missing function identifier');
  }
  $this->t
    ->mustMatch(OP_LEFT_PAREN);
  $f->params = array();
  while (($tt = $this->t
    ->get()) != OP_RIGHT_PAREN) {
    if ($tt != TOKEN_IDENTIFIER) {
      throw $this->t
        ->newSyntaxError('Missing formal parameter');
    }
    array_push($f->params, $this->t
      ->currentToken()->value);
    if ($this->t
      ->peek() != OP_RIGHT_PAREN) {
      $this->t
        ->mustMatch(OP_COMMA);
    }
  }
  $this->t
    ->mustMatch(OP_LEFT_CURLY);
  $x2 = new JSCompilerContext(true);
  $f->body = $this
    ->Script($x2);
  $this->t
    ->mustMatch(OP_RIGHT_CURLY);
  $f->end = $this->t
    ->currentToken()->end;
  $f->functionForm = $functionForm;
  if ($functionForm == DECLARED_FORM) {
    array_push($x->funDecls, $f);
  }
  return $f;
}