private function JSParser::FunctionDefinition in Javascript Aggregator 6
2 calls to JSParser::FunctionDefinition()
File
- ./
jsminplus.php, line 1108
Class
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;
}