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

Breadcrumb

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

function Parser::parsePropertyDefinition

Parses a property in an object literal

Return value

Node\Property|null

1 call to Parser::parsePropertyDefinition()
Parser::parseObjectLiteral in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses an object literal

File

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

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parsePropertyDefinition() {
    if ($this->features->restSpreadProperties && ($prop = $this->parseSpreadElement())) {
        return $prop;
    }
    $state = $this->scanner
        ->getState();
    if (($property = $this->parsePropertyName()) && $this->scanner
        ->consume(":")) {
        $value = $this->isolateContext(array(
            "allowIn" => true,
        ), "parseAssignmentExpression");
        if ($value) {
            $startPos = isset($property[2]) ? $property[2] : $property[0];
            $node = $this->createNode("Property", $startPos);
            $node->setKey($property[0]);
            $node->setValue($value);
            $node->setComputed($property[1]);
            return $this->completeNode($node);
        }
        $this->error();
    }
    $this->scanner
        ->setState($state);
    if ($property = $this->parseMethodDefinition()) {
        $node = $this->createNode("Property", $property);
        $node->setKey($property->getKey());
        $node->setValue($property->getValue());
        $node->setComputed($property->getComputed());
        $kind = $property->getKind();
        if ($kind !== Node\MethodDefinition::KIND_GET && $kind !== Node\MethodDefinition::KIND_SET) {
            $node->setMethod(true);
            $node->setKind(Node\Property::KIND_INIT);
        }
        else {
            $node->setKind($kind);
        }
        return $this->completeNode($node);
    }
    elseif ($key = $this->parseIdentifier(static::$identifierReference)) {
        $node = $this->createNode("Property", $key);
        $node->setShorthand(true);
        $node->setKey($key);
        $value = $this->isolateContext(array(
            "allowIn" => true,
        ), "parseInitializer");
        $node->setValue($value ?: $key);
        return $this->completeNode($node);
    }
    return null;
}

API Navigation

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