Skip to content

Commit

Permalink
yield can retun null
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 21, 2022
1 parent 61d72cf commit 30c1511
Show file tree
Hide file tree
Showing 37 changed files with 47 additions and 95 deletions.
1 change: 0 additions & 1 deletion src/Latte/Compiler/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ abstract public function print(PrintContext $context): string;

public function &getIterator(): \Generator
{
return;
yield;
}
}
3 changes: 3 additions & 0 deletions src/Latte/Compiler/NodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private function traverseNode(Node $node): Node

if ($children) {
foreach ($node as &$subnode) {
if ($subnode === null) {
continue;
}
$subnode = $this->traverseNode($subnode);
if ($this->stop) {
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/AuxiliaryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Compiler/Nodes/Html/AttributeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public function print(PrintContext $context): string
public function &getIterator(): \Generator
{
yield $this->name;
if ($this->value) {
yield $this->value;
}
yield $this->value;
}
}
12 changes: 3 additions & 9 deletions src/Latte/Compiler/Nodes/Html/ElementNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,8 @@ private function printStartTag(PrintContext $context): string
public function &getIterator(): \Generator
{
yield $this->tagNode;
if ($this->customName) {
yield $this->customName;
}
if ($this->attributes) {
yield $this->attributes;
}
if ($this->content) {
yield $this->content;
}
yield $this->customName;
yield $this->attributes;
yield $this->content;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/NopNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Compiler/Nodes/Php/ArgumentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
if ($this->name) {
yield $this->name;
}
yield $this->name;
yield $this->value;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function print(PrintContext $context): string
public function &getIterator(): \Generator
{
yield $this->expr;
if ($this->index) {
yield $this->index;
}
yield $this->index;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
if ($this->key) {
yield $this->key;
}
yield $this->key;
yield $this->value;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public function print(PrintContext $context): string
public function &getIterator(): \Generator
{
foreach ($this->items as &$item) {
if ($item) {
yield $item;
}
yield $item;
}
}
}
8 changes: 2 additions & 6 deletions src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public function &getIterator(): \Generator
yield $item;
}

if ($this->returnType) {
yield $this->returnType;
}
if ($this->expr) {
yield $this->expr;
}
yield $this->returnType;
yield $this->expr;
}
}
8 changes: 2 additions & 6 deletions src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public function print(PrintContext $context): string
public function &getIterator(): \Generator
{
yield $this->cond;
if ($this->if) {
yield $this->if;
}
if ($this->else) {
yield $this->else;
}
yield $this->if;
yield $this->else;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/Php/IdentifierNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/Php/NameNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public function toCodeString(): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
8 changes: 2 additions & 6 deletions src/Latte/Compiler/Nodes/Php/ParameterNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
if ($this->type) {
yield $this->type;
}
yield $this->type;
yield $this->var;
if ($this->default) {
yield $this->default;
}
yield $this->default;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/Php/ScalarNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ abstract class ScalarNode extends ExpressionNode
{
public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Compiler/Nodes/TextNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function isWhitespace(): bool

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/ContentTypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/DebugbreakNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
if ($this->condition) {
yield $this->condition;
}
yield $this->condition;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/DumpNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
if ($this->expression) {
yield $this->expression;
}
yield $this->expression;
}
}
8 changes: 2 additions & 6 deletions src/Latte/Essential/Nodes/FirstLastSepNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
if ($this->width) {
yield $this->width;
}
yield $this->width;
yield $this->then;
if ($this->else) {
yield $this->else;
}
yield $this->else;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/ForNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public function &getIterator(): \Generator
yield $item;
}

if ($this->condition) {
yield $this->condition;
}
yield $this->condition;

foreach ($this->next as &$item) {
yield $item;
Expand Down
8 changes: 2 additions & 6 deletions src/Latte/Essential/Nodes/ForeachNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,9 @@ private function printArgs(PrintContext $context): string
public function &getIterator(): \Generator
{
yield $this->expression;
if ($this->key) {
yield $this->key;
}
yield $this->key;
yield $this->value;
yield $this->content;
if ($this->else) {
yield $this->else;
}
yield $this->else;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/IfChangedNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ public function &getIterator(): \Generator
{
yield $this->conditions;
yield $this->then;
if ($this->else) {
yield $this->else;
}
yield $this->else;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/IfNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ public function &getIterator(): \Generator
{
yield $this->condition;
yield $this->then;
if ($this->else) {
yield $this->else;
}
yield $this->else;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/IncludeBlockNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ private function printBlockFrom(PrintContext $context, string $modArg): string
public function &getIterator(): \Generator
{
yield $this->name;
if ($this->from) {
yield $this->from;
}
yield $this->from;
yield $this->args;
yield $this->modifier;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/RawPhpNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/RollbackNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/SwitchNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public function &getIterator(): \Generator
{
yield $this->expression;
foreach ($this->cases as [&$case, , &$stmt]) {
if ($case) {
yield $case;
}
yield $case;
yield $stmt;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/TemplatePrintNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/TemplateTypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/TraceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
4 changes: 1 addition & 3 deletions src/Latte/Essential/Nodes/TryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function print(PrintContext $context): string
public function &getIterator(): \Generator
{
yield $this->try;
if ($this->else) {
yield $this->else;
}
yield $this->else;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/VarPrintNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/VarTypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function print(PrintContext $context): string

public function &getIterator(): \Generator
{
false && yield;
yield;
}
}
4 changes: 3 additions & 1 deletion tests/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ function exportAST(Node $node)
};
$res = $prop ? $prop . "\n" : '';
foreach ($node as $sub) {
$res .= rtrim(exportAST($sub), "\n") . "\n";
if ($sub !== null) {
$res .= rtrim(exportAST($sub), "\n") . "\n";
}
}

return substr($node::class, strrpos($node::class, '\\') + 1, -4)
Expand Down

0 comments on commit 30c1511

Please sign in to comment.