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

Breadcrumb

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

function Parser::parseImportDeclaration

Parses an import declaration

Return value

Node\ModuleDeclaration|null

1 call to Parser::parseImportDeclaration()
Parser::parseModuleItem in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses a module item

File

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

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parseImportDeclaration() {
    
    //Delay parsing of dynamic import so that it is handled
    
    //by the relative method
    if ($this->features->dynamicImport && $this->scanner
        ->isBefore(array(
        array(
            "import",
            "(",
        ),
    ), true)) {
        return null;
    }
    
    //Delay parsing of import.meta so that it is handled
    
    //by the relative method
    if ($this->features->importMeta && $this->scanner
        ->isBefore(array(
        array(
            "import",
            ".",
        ),
    ), true)) {
        return null;
    }
    if ($token = $this->scanner
        ->consume("import")) {
        if ($source = $this->parseStringLiteral()) {
            $this->assertEndOfStatement();
            $node = $this->createNode("ImportDeclaration", $token);
            $node->setSource($source);
            return $this->completeNode($node);
        }
        elseif (($specifiers = $this->parseImportClause()) !== null && ($source = $this->parseFromClause())) {
            $this->assertEndOfStatement();
            $node = $this->createNode("ImportDeclaration", $token);
            $node->setSpecifiers($specifiers);
            $node->setSource($source);
            return $this->completeNode($node);
        }
        $this->error();
    }
    return null;
}

API Navigation

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