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

Breadcrumb

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

function Parser::parseForNotVarLetConstStatement

Parses a for statement that does not start with var, let or const

Parameters

Token $forToken Token that corresponds to the "for" keyword:

bool $hasAwait True if "for" is followed by "await":

Return value

Node\Node|null

1 call to Parser::parseForNotVarLetConstStatement()
Parser::parseIterationStatement in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses do-while, while, for, for-in and for-of statements

File

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

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parseForNotVarLetConstStatement($forToken, $hasAwait) {
    $state = $this->scanner
        ->getState();
    $notBeforeSB = !$this->scanner
        ->isBefore(array(
        array(
            "let",
            "[",
        ),
    ), true);
    if ($notBeforeSB && (($init = $this->isolateContext(array(
        "allowIn" => false,
    ), "parseExpression")) || true) && $this->scanner
        ->consume(";")) {
        $test = $this->isolateContext(array(
            "allowIn" => true,
        ), "parseExpression");
        if ($this->scanner
            ->consume(";")) {
            $update = $this->isolateContext(array(
                "allowIn" => true,
            ), "parseExpression");
            if ($this->scanner
                ->consume(")") && ($body = $this->parseStatement())) {
                $node = $this->createNode("ForStatement", $forToken);
                $node->setInit($init);
                $node->setTest($test);
                $node->setUpdate($update);
                $node->setBody($body);
                return $this->completeNode($node);
            }
        }
    }
    else {
        $this->scanner
            ->setState($state);
        $beforeLetAsyncOf = $this->scanner
            ->isBefore(array(
            "let",
            array(
                "async",
                "of",
            ),
        ), true);
        $left = $this->parseLeftHandSideExpression();
        if ($left && $left->getType() === "ChainExpression") {
            $this->error("Optional chain can't appear in left-hand side");
        }
        $left = $this->expressionToPattern($left);
        if ($notBeforeSB && $left && $this->scanner
            ->consume("in")) {
            if (($right = $this->isolateContext(array(
                "allowIn" => true,
            ), "parseExpression")) && $this->scanner
                ->consume(")") && ($body = $this->parseStatement())) {
                $node = $this->createNode("ForInStatement", $forToken);
                $node->setLeft($left);
                $node->setRight($right);
                $node->setBody($body);
                return $this->completeNode($node);
            }
        }
        elseif (($hasAwait || !$beforeLetAsyncOf) && $left && $this->scanner
            ->consume("of")) {
            if (($right = $this->isolateContext(array(
                "allowIn" => true,
            ), "parseAssignmentExpression")) && $this->scanner
                ->consume(")") && ($body = $this->parseStatement())) {
                $node = $this->createNode("ForOfStatement", $forToken);
                $node->setLeft($left);
                $node->setRight($right);
                $node->setBody($body);
                return $this->completeNode($node);
            }
        }
    }
    $this->error();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal