function Parser::parseUnaryExpression
Parses a unary expression
Return value
Node\Node|null
1 call to Parser::parseUnaryExpression()
- Parser::parseLogicalBinaryExpression in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a logical or a binary expression
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php, line 3224
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseUnaryExpression() {
$operators = $this->unaryOperators;
if ($this->features->asyncAwait && $this->context->allowAwait) {
$operators[] = "await";
}
if ($expr = $this->parsePostfixExpression()) {
return $expr;
}
elseif ($token = $this->scanner
->consumeOneOf($operators)) {
if ($argument = $this->parseUnaryExpression()) {
$op = $token->value;
//Deleting a variable without accessing its properties is a
//syntax error in strict mode
if ($op === "delete" && $this->scanner
->getStrictMode() && $argument instanceof Node\Identifier) {
$this->error("Deleting an unqualified identifier is not allowed in strict mode");
}
if ($this->features->asyncAwait && $op === "await") {
$node = $this->createNode("AwaitExpression", $token);
}
else {
if ($op === "++" || $op === "--") {
if ($argument->getType() === "ChainExpression") {
$this->error("Optional chain can't appear in left-hand side");
}
$node = $this->createNode("UpdateExpression", $token);
$node->setPrefix(true);
}
else {
$node = $this->createNode("UnaryExpression", $token);
}
$node->setOperator($op);
}
$node->setArgument($argument);
return $this->completeNode($node);
}
$this->error();
}
return null;
}