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

Breadcrumb

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

function Parser::parseFormalParameterList

Parses a parameter list

Return value

Node\Node[]|null

1 call to Parser::parseFormalParameterList()
Parser::parseArrowParameters in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses parameters in an arrow function. If the parameters are wrapped in round brackets, the returned value is an array where the first element is the parameters list and the second element is the open round brackets, this is needed to know the start…

File

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

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parseFormalParameterList() {
    $hasComma = false;
    $list = array();
    while (($param = $this->parseBindingRestElement()) || ($param = $this->parseBindingElement())) {
        $hasComma = false;
        $list[] = $param;
        if ($param->getType() === "RestElement") {
            break;
        }
        elseif ($this->scanner
            ->consume(",")) {
            $hasComma = true;
        }
        else {
            break;
        }
    }
    
    //Check if it ends with a comma, then check if the comma is a trailing comma,
    
    //in that case throw an error if the trailing comma feature is not enabled
    if ($hasComma && !$this->features->trailingCommaFunctionCallDeclaration) {
        $token = $this->scanner
            ->getToken();
        if ($token && $token->value === ")") {
            $this->error();
        }
    }
    return $list;
}

API Navigation

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