function Parser::parseFunctionOrGeneratorExpression
Parses function or generator expression
Return value
Node\FunctionExpression|null
1 call to Parser::parseFunctionOrGeneratorExpression()
- Parser::parsePrimaryExpression in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a primary expression
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php, line 1496
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseFunctionOrGeneratorExpression() {
$allowGenerator = true;
$async = false;
if ($this->features->asyncAwait && ($async = $this->checkAsyncFunctionStart())) {
$this->scanner
->consumeToken();
if (!$this->features->asyncIterationGenerators) {
$allowGenerator = false;
}
}
if ($token = $this->scanner
->consume("function")) {
$generator = $allowGenerator && $this->scanner
->consume("*");
if ($generator || $async) {
$flags = array(
null,
);
if ($generator) {
$flags["allowYield"] = true;
}
if ($async) {
$flags["allowAwait"] = true;
}
}
else {
$flags = null;
}
$id = $this->isolateContext($flags, "parseIdentifier", array(
static::$bindingIdentifier,
));
if ($this->scanner
->consume("(") && ($params = $this->isolateContext($flags, "parseFormalParameterList")) !== null && $this->scanner
->consume(")") && ($tokenBodyStart = $this->scanner
->consume("{")) && (($body = $this->isolateContext($flags, "parseFunctionBody")) || true) && $this->scanner
->consume("}")) {
$body->location->start = $tokenBodyStart->location->start;
$body->location->end = $this->scanner
->getPosition();
$node = $this->createNode("FunctionExpression", $async ?: $token);
$node->setId($id);
$node->setParams($params);
$node->setBody($body);
$node->setGenerator($generator);
$node->setAsync((bool) $async);
return $this->completeNode($node);
}
$this->error();
}
return null;
}