Skip to content

Commit 30c1511

Browse files
committed
yield can retun null
1 parent 61d72cf commit 30c1511

37 files changed

+47
-95
lines changed

src/Latte/Compiler/Node.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ abstract public function print(PrintContext $context): string;
2222

2323
public function &getIterator(): \Generator
2424
{
25-
return;
2625
yield;
2726
}
2827
}

src/Latte/Compiler/NodeTraverser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ private function traverseNode(Node $node): Node
5656

5757
if ($children) {
5858
foreach ($node as &$subnode) {
59+
if ($subnode === null) {
60+
continue;
61+
}
5962
$subnode = $this->traverseNode($subnode);
6063
if ($this->stop) {
6164
break;

src/Latte/Compiler/Nodes/AuxiliaryNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public function print(PrintContext $context): string
2828

2929
public function &getIterator(): \Generator
3030
{
31-
false && yield;
31+
yield;
3232
}
3333
}

src/Latte/Compiler/Nodes/Html/AttributeNode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function print(PrintContext $context): string
4141
public function &getIterator(): \Generator
4242
{
4343
yield $this->name;
44-
if ($this->value) {
45-
yield $this->value;
46-
}
44+
yield $this->value;
4745
}
4846
}

src/Latte/Compiler/Nodes/Html/ElementNode.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,8 @@ private function printStartTag(PrintContext $context): string
116116
public function &getIterator(): \Generator
117117
{
118118
yield $this->tagNode;
119-
if ($this->customName) {
120-
yield $this->customName;
121-
}
122-
if ($this->attributes) {
123-
yield $this->attributes;
124-
}
125-
if ($this->content) {
126-
yield $this->content;
127-
}
119+
yield $this->customName;
120+
yield $this->attributes;
121+
yield $this->content;
128122
}
129123
}

src/Latte/Compiler/Nodes/NopNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public function print(PrintContext $context): string
2222

2323
public function &getIterator(): \Generator
2424
{
25-
false && yield;
25+
yield;
2626
}
2727
}

src/Latte/Compiler/Nodes/Php/ArgumentNode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public function print(PrintContext $context): string
3737

3838
public function &getIterator(): \Generator
3939
{
40-
if ($this->name) {
41-
yield $this->name;
42-
}
40+
yield $this->name;
4341
yield $this->value;
4442
}
4543
}

src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public function print(PrintContext $context): string
3434
public function &getIterator(): \Generator
3535
{
3636
yield $this->expr;
37-
if ($this->index) {
38-
yield $this->index;
39-
}
37+
yield $this->index;
4038
}
4139
}

src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function print(PrintContext $context): string
4444

4545
public function &getIterator(): \Generator
4646
{
47-
if ($this->key) {
48-
yield $this->key;
49-
}
47+
yield $this->key;
5048
yield $this->value;
5149
}
5250
}

src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ public function print(PrintContext $context): string
8686
public function &getIterator(): \Generator
8787
{
8888
foreach ($this->items as &$item) {
89-
if ($item) {
90-
yield $item;
91-
}
89+
yield $item;
9290
}
9391
}
9492
}

0 commit comments

Comments
 (0)