class TemplateLiteral
A node that represents a template literal. For example: `this is a ${test()} template`
@author Marco Marchiò <marco.mm89@gmail.com>
Hierarchy
- class \Peast\Syntax\Node\Node implements \Peast\Syntax\Node\JSONSerializable
- class \Peast\Syntax\Node\TemplateLiteral extends \Peast\Syntax\Node\Node implements \Peast\Syntax\Node\Expression
Expanded class hierarchy of TemplateLiteral
2 string references to 'TemplateLiteral'
- Parser::parseTemplateLiteral in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a template literal
- Renderer::renderNode in vendor/
mck89/ peast/ lib/ Peast/ Renderer.php - Renders a node
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ TemplateLiteral.php, line 18
Namespace
Peast\Syntax\NodeView source
class TemplateLiteral extends Node implements Expression {
/**
* Map of node properties
*
* @var array
*/
protected $propertiesMap = array(
"parts" => true,
"quasis" => false,
"expressions" => false,
);
/**
* Array of quasis that are the literal parts of the template
*
* @var TemplateElement[]
*/
protected $quasis = array();
/**
* Array of expressions inside the template
*
* @var Expression[]
*/
protected $expressions = array();
/**
* Returns the array of quasis that are the literal parts of the template
*
* @return TemplateElement[]
*/
public function getQuasis() {
return $this->quasis;
}
/**
* Sets the array of quasis that are the literal parts of the template
*
* @param TemplateElement[] $quasis Quasis
*
* @return $this
*/
public function setQuasis($quasis) {
$this->assertArrayOf($quasis, "TemplateElement");
$this->quasis = $quasis;
return $this;
}
/**
* Returns the array of expressions inside the template
*
* @return Expression[]
*/
public function getExpressions() {
return $this->expressions;
}
/**
* Sets the array of expressions inside the template
*
* @param Expression[] $expressions Expressions
*
* @return $this
*/
public function setExpressions($expressions) {
$this->assertArrayOf($expressions, "Expression");
$this->expressions = $expressions;
return $this;
}
/**
* Returns an array of the template parts (quasis and expressions)
*
* @return array
*/
public function getParts() {
// It must be a list of quasis and expressions alternated
$parts = array();
foreach ($this->quasis as $k => $val) {
$parts[] = $val;
if (isset($this->expressions[$k])) {
$parts[] = $this->expressions[$k];
}
}
return $parts;
}
/**
* Sets the array of the template parts (quasis and expressions)
*
* @param array Template parts
*
* @return $this
*/
public function setParts($parts) {
$this->assertArrayOf($parts, array(
"Expression",
"TemplateElement",
));
$quasis = $expressions = array();
foreach ($parts as $part) {
if ($part instanceof TemplateElement) {
$quasis[] = $part;
}
else {
$expressions[] = $part;
}
}
return $this->setQuasis($quasis)
->setExpressions($expressions);
}
/**
* Returns a serializable version of the node
*
* @return array
*/
public function jsonSerialize() {
$ret = parent::jsonSerialize();
unset($ret["parts"]);
return $ret;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Node::$leadingComments | protected | property | Leading comments array | ||
Node::$location | public | property | Node location in the source code | ||
Node::$trailingComments | protected | property | Trailing comments array | ||
Node::assertArrayOf | protected | function | Asserts that the given value is an array of defined type | ||
Node::assertType | protected | function | Asserts that the given value respects the defined type | ||
Node::getLeadingComments | public | function | Returns leading comments array | ||
Node::getLocation | public | function | Returns node location in the source code | ||
Node::getTrailingComments | public | function | Returns trailing comments array | ||
Node::getType | public | function | Returns node type | 2 | |
Node::render | public | function | Renders the current node | ||
Node::setEndPosition | public | function | Sets the end position of the node in the source code | ||
Node::setLeadingComments | public | function | Sets leading comments array | 1 | |
Node::setStartPosition | public | function | Sets the start position of the node in the source code | ||
Node::setTrailingComments | public | function | Sets trailing comments array | 1 | |
Node::traverse | public | function | Traverses the current node and all its child nodes using the given function |
||
Node::typeError | protected | function | Throws an error if the defined type is not supported b | ||
Node::__construct | public | function | Class constructor | ||
TemplateLiteral::$expressions | protected | property | Array of expressions inside the template | ||
TemplateLiteral::$propertiesMap | protected | property | Map of node properties | Overrides Node::$propertiesMap | |
TemplateLiteral::$quasis | protected | property | Array of quasis that are the literal parts of the template | ||
TemplateLiteral::getExpressions | public | function | Returns the array of expressions inside the template | ||
TemplateLiteral::getParts | public | function | Returns an array of the template parts (quasis and expressions) | ||
TemplateLiteral::getQuasis | public | function | Returns the array of quasis that are the literal parts of the template | ||
TemplateLiteral::jsonSerialize | public | function | Returns a serializable version of the node | Overrides Node::jsonSerialize | |
TemplateLiteral::setExpressions | public | function | Sets the array of expressions inside the template | ||
TemplateLiteral::setParts | public | function | Sets the array of the template parts (quasis and expressions) | ||
TemplateLiteral::setQuasis | public | function | Sets the array of quasis that are the literal parts of the template |