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\SyntaxCode
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;
}