function Parser::parseFunctionOrGeneratorDeclaration
Parses function or generator declaration
Parameters
bool $default Default mode:
bool $allowGenerator True to allow parsing of generators:
Return value
Node\FunctionDeclaration|null
3 calls to Parser::parseFunctionOrGeneratorDeclaration()
- Parser::parseDeclaration in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a declaration
- Parser::parseIfStatement in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses an if statement
- Parser::parseLabelledStatement in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a labelled statement
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php, line 1427
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseFunctionOrGeneratorDeclaration($default = false, $allowGenerator = true) {
$async = null;
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("*");
$id = $this->parseIdentifier(static::$bindingIdentifier);
if ($generator || $async) {
$flags = array(
null,
);
if ($generator) {
$flags["allowYield"] = true;
}
if ($async) {
$flags["allowAwait"] = true;
}
}
else {
$flags = null;
}
if (($default || $id) && $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("FunctionDeclaration", $async ?: $token);
if ($id) {
$node->setId($id);
}
$node->setParams($params);
$node->setBody($body);
$node->setGenerator($generator);
$node->setAsync((bool) $async);
return $this->completeNode($node);
}
$this->error();
}
return null;
}