function Parser::parseExportDeclaration
Parses an export declaration
Return value
Node\ModuleDeclaration|null
1 call to Parser::parseExportDeclaration()
- 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 2025
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseExportDeclaration() {
if ($token = $this->scanner
->consume("export")) {
if ($this->scanner
->consume("*")) {
$exported = null;
if ($this->features->exportedNameInExportAll && $this->scanner
->consume("as")) {
$exported = $this->parseModuleExportName();
if (!$exported) {
$this->error();
}
}
if ($source = $this->parseFromClause()) {
$this->assertEndOfStatement();
$node = $this->createNode("ExportAllDeclaration", $token);
$node->setSource($source);
$node->setExported($exported);
return $this->completeNode($node);
}
}
elseif ($this->scanner
->consume("default")) {
$lookaheadTokens = array(
"function",
"class",
);
if ($this->features->asyncAwait) {
$lookaheadTokens[] = array(
"async",
true,
);
}
if (($declaration = $this->isolateContext(array(
"allowAwait" => $this->features->topLevelAwait,
), "parseFunctionOrGeneratorDeclaration", array(
true,
))) || ($declaration = $this->isolateContext(array(
"allowAwait" => $this->features->topLevelAwait,
), "parseClassDeclaration", array(
true,
)))) {
$node = $this->createNode("ExportDefaultDeclaration", $token);
$node->setDeclaration($declaration);
return $this->completeNode($node);
}
elseif (!$this->scanner
->isBefore($lookaheadTokens, $this->features->asyncAwait) && ($declaration = $this->isolateContext(array(
"allowIn" => true,
"allowAwait" => $this->features->topLevelAwait,
), "parseAssignmentExpression"))) {
$this->assertEndOfStatement();
$node = $this->createNode("ExportDefaultDeclaration", $token);
$node->setDeclaration($declaration);
return $this->completeNode($node);
}
}
elseif (($specifiers = $this->parseExportClause()) !== null) {
$node = $this->createNode("ExportNamedDeclaration", $token);
$node->setSpecifiers($specifiers);
if ($source = $this->parseFromClause()) {
$node->setSource($source);
}
$this->assertEndOfStatement();
return $this->completeNode($node);
}
elseif (($dec = $this->isolateContext(array(
"allowAwait" => $this->features->topLevelAwait,
), "parseVariableStatement")) || ($dec = $this->isolateContext(array(
"allowAwait" => $this->features->topLevelAwait,
), "parseDeclaration"))) {
$node = $this->createNode("ExportNamedDeclaration", $token);
$node->setDeclaration($dec);
return $this->completeNode($node);
}
$this->error();
}
return null;
}