function Parser::parseLexicalDeclaration
Parses a let or const declaration
Return value
Node\VariableDeclaration|null
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php, line 1837
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseLexicalDeclaration() {
$state = $this->scanner
->getState();
if ($token = $this->scanner
->consumeOneOf(array(
"let",
"const",
))) {
$declarations = $this->charSeparatedListOf("parseVariableDeclaration");
if ($declarations) {
$this->assertEndOfStatement();
$node = $this->createNode("VariableDeclaration", $token);
$node->setKind($token->value);
$node->setDeclarations($declarations);
return $this->completeNode($node);
}
// "let" can be used as variable name in non-strict mode
if ($this->scanner
->getStrictMode() || $token->value !== "let") {
$this->error();
}
else {
$this->scanner
->setState($state);
}
}
return null;
}