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

Breadcrumb

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

function Parser::parseJSXAttribute

Parses a jsx spread attribute

Return value

\Peast\Syntax\Node\JSX\JSXSpreadAttribute|null

1 call to Parser::parseJSXAttribute()
Parser::parseJSXAttributes in vendor/mck89/peast/lib/Peast/Syntax/JSX/Parser.php
Parses a jsx attributes list

File

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

Class

Parser
JSX parser trait

Namespace

Peast\Syntax\JSX

Code

protected function parseJSXAttribute() {
    if (!($name = $this->parseJSXIdentifierOrMemberExpression(false))) {
        return null;
    }
    $value = null;
    if ($this->scanner
        ->consume("=")) {
        $strToken = $this->scanner
            ->reconsumeCurrentTokenInJSXMode();
        if ($strToken && $strToken->type === Token::TYPE_STRING_LITERAL) {
            $this->scanner
                ->consumeToken();
            $value = $this->createNode("StringLiteral", $strToken);
            $value->setRaw($strToken->value);
            $value = $this->completeNode($value);
        }
        elseif ($startExp = $this->scanner
            ->consume("{")) {
            if (($exp = $this->parseAssignmentExpression()) && $this->scanner
                ->consume("}")) {
                $value = $this->createJSXNode("JSXExpressionContainer", $startExp);
                $value->setExpression($exp);
                $value = $this->completeNode($value);
            }
            else {
                $this->error();
            }
        }
        elseif (!($value = $this->parseJSXFragment()) && !($value = $this->parseJSXElement())) {
            $this->error();
        }
    }
    $node = $this->createJSXNode("JSXAttribute", $name);
    $node->setName($name);
    if ($value) {
        $node->setValue($value);
    }
    return $this->completeNode($node);
}

API Navigation

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