Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Parser.php

function Parser::parseAssignmentExpression

Parses an assignment expression

Return value

Node\Node|null

2 calls to Parser::parseAssignmentExpression()
Parser::parseConditionalExpression in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses a conditional expression
Parser::parseInitializer in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses an initializer

File

vendor/mck89/peast/lib/Peast/Syntax/Parser.php, line 3053

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parseAssignmentExpression() {
    if ($expr = $this->parseArrowFunction()) {
        return $expr;
    }
    elseif ($this->context->allowYield && ($expr = $this->parseYieldExpression())) {
        return $expr;
    }
    elseif ($expr = $this->parseConditionalExpression()) {
        $exprTypes = array(
            "ConditionalExpression",
            "LogicalExpression",
            "BinaryExpression",
            "UpdateExpression",
            "UnaryExpression",
        );
        if (!in_array($expr->getType(), $exprTypes)) {
            $operators = $this->assignmentOperators;
            if ($operator = $this->scanner
                ->consumeOneOf($operators)) {
                if ($expr->getType() === "ChainExpression") {
                    $this->error("Optional chain can't appear in left-hand side");
                }
                $right = $this->parseAssignmentExpression();
                if ($right) {
                    $node = $this->createNode("AssignmentExpression", $expr);
                    $node->setLeft($this->expressionToPattern($expr));
                    $node->setOperator($operator->value);
                    $node->setRight($right);
                    return $this->completeNode($node);
                }
                $this->error();
            }
        }
        return $expr;
    }
    return null;
}
RSS feed
Powered by Drupal