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

-1
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

+3
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

+1-1
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

+1-3
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

+3-9
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

+1-1
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

+1-3
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

+1-3
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

+1-3
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

+1-3
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
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ public function &getIterator(): \Generator
6363
yield $item;
6464
}
6565

66-
if ($this->returnType) {
67-
yield $this->returnType;
68-
}
69-
if ($this->expr) {
70-
yield $this->expr;
71-
}
66+
yield $this->returnType;
67+
yield $this->expr;
7268
}
7369
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ public function print(PrintContext $context): string
4040
public function &getIterator(): \Generator
4141
{
4242
yield $this->cond;
43-
if ($this->if) {
44-
yield $this->if;
45-
}
46-
if ($this->else) {
47-
yield $this->else;
48-
}
43+
yield $this->if;
44+
yield $this->else;
4945
}
5046
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ public function print(PrintContext $context): string
3737

3838
public function &getIterator(): \Generator
3939
{
40-
false && yield;
40+
yield;
4141
}
4242
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ public function toCodeString(): string
9090

9191
public function &getIterator(): \Generator
9292
{
93-
false && yield;
93+
yield;
9494
}
9595
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ public function print(PrintContext $context): string
4343

4444
public function &getIterator(): \Generator
4545
{
46-
if ($this->type) {
47-
yield $this->type;
48-
}
46+
yield $this->type;
4947
yield $this->var;
50-
if ($this->default) {
51-
yield $this->default;
52-
}
48+
yield $this->default;
5349
}
5450
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ abstract class ScalarNode extends ExpressionNode
1414
{
1515
public function &getIterator(): \Generator
1616
{
17-
false && yield;
17+
yield;
1818
}
1919
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public function print(PrintContext $context): string
3030

3131
public function &getIterator(): \Generator
3232
{
33-
false && yield;
33+
yield;
3434
}
3535
}

src/Latte/Compiler/Nodes/TextNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public function isWhitespace(): bool
3838

3939
public function &getIterator(): \Generator
4040
{
41-
false && yield;
41+
yield;
4242
}
4343
}

src/Latte/Essential/Nodes/ContentTypeNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ public function print(PrintContext $context): string
7575

7676
public function &getIterator(): \Generator
7777
{
78-
false && yield;
78+
yield;
7979
}
8080
}

src/Latte/Essential/Nodes/DebugbreakNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public function print(PrintContext $context): string
4646

4747
public function &getIterator(): \Generator
4848
{
49-
if ($this->condition) {
50-
yield $this->condition;
51-
}
49+
yield $this->condition;
5250
}
5351
}

src/Latte/Essential/Nodes/DumpNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public function print(PrintContext $context): string
5151

5252
public function &getIterator(): \Generator
5353
{
54-
if ($this->expression) {
55-
yield $this->expression;
56-
}
54+
yield $this->expression;
5755
}
5856
}

src/Latte/Essential/Nodes/FirstLastSepNode.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ public function print(PrintContext $context): string
7070

7171
public function &getIterator(): \Generator
7272
{
73-
if ($this->width) {
74-
yield $this->width;
75-
}
73+
yield $this->width;
7674
yield $this->then;
77-
if ($this->else) {
78-
yield $this->else;
79-
}
75+
yield $this->else;
8076
}
8177
}

src/Latte/Essential/Nodes/ForNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ public function &getIterator(): \Generator
7878
yield $item;
7979
}
8080

81-
if ($this->condition) {
82-
yield $this->condition;
83-
}
81+
yield $this->condition;
8482

8583
foreach ($this->next as &$item) {
8684
yield $item;

src/Latte/Essential/Nodes/ForeachNode.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,9 @@ private function printArgs(PrintContext $context): string
143143
public function &getIterator(): \Generator
144144
{
145145
yield $this->expression;
146-
if ($this->key) {
147-
yield $this->key;
148-
}
146+
yield $this->key;
149147
yield $this->value;
150148
yield $this->content;
151-
if ($this->else) {
152-
yield $this->else;
153-
}
149+
yield $this->else;
154150
}
155151
}

src/Latte/Essential/Nodes/IfChangedNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ public function &getIterator(): \Generator
134134
{
135135
yield $this->conditions;
136136
yield $this->then;
137-
if ($this->else) {
138-
yield $this->else;
139-
}
137+
yield $this->else;
140138
}
141139
}

src/Latte/Essential/Nodes/IfNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ public function &getIterator(): \Generator
173173
{
174174
yield $this->condition;
175175
yield $this->then;
176-
if ($this->else) {
177-
yield $this->else;
178-
}
176+
yield $this->else;
179177
}
180178
}

src/Latte/Essential/Nodes/IncludeBlockNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ private function printBlockFrom(PrintContext $context, string $modArg): string
131131
public function &getIterator(): \Generator
132132
{
133133
yield $this->name;
134-
if ($this->from) {
135-
yield $this->from;
136-
}
134+
yield $this->from;
137135
yield $this->args;
138136
yield $this->modifier;
139137
}

src/Latte/Essential/Nodes/RawPhpNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function print(PrintContext $context): string
4747

4848
public function &getIterator(): \Generator
4949
{
50-
false && yield;
50+
yield;
5151
}
5252
}

src/Latte/Essential/Nodes/RollbackNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public function print(PrintContext $context): string
3838

3939
public function &getIterator(): \Generator
4040
{
41-
false && yield;
41+
yield;
4242
}
4343
}

src/Latte/Essential/Nodes/SwitchNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ public function &getIterator(): \Generator
109109
{
110110
yield $this->expression;
111111
foreach ($this->cases as [&$case, , &$stmt]) {
112-
if ($case) {
113-
yield $case;
114-
}
112+
yield $case;
115113
yield $stmt;
116114
}
117115
}

src/Latte/Essential/Nodes/TemplatePrintNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public function print(PrintContext $context): string
4040

4141
public function &getIterator(): \Generator
4242
{
43-
false && yield;
43+
yield;
4444
}
4545
}

src/Latte/Essential/Nodes/TemplateTypeNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public function print(PrintContext $context): string
3939

4040
public function &getIterator(): \Generator
4141
{
42-
false && yield;
42+
yield;
4343
}
4444
}

src/Latte/Essential/Nodes/TraceNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function print(PrintContext $context): string
3636

3737
public function &getIterator(): \Generator
3838
{
39-
false && yield;
39+
yield;
4040
}
4141
}

src/Latte/Essential/Nodes/TryNode.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public function print(PrintContext $context): string
6868
public function &getIterator(): \Generator
6969
{
7070
yield $this->try;
71-
if ($this->else) {
72-
yield $this->else;
73-
}
71+
yield $this->else;
7472
}
7573
}

src/Latte/Essential/Nodes/VarPrintNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public function print(PrintContext $context): string
4141

4242
public function &getIterator(): \Generator
4343
{
44-
false && yield;
44+
yield;
4545
}
4646
}

src/Latte/Essential/Nodes/VarTypeNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ public function print(PrintContext $context): string
3737

3838
public function &getIterator(): \Generator
3939
{
40-
false && yield;
40+
yield;
4141
}
4242
}

tests/helpers.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ function exportAST(Node $node)
126126
};
127127
$res = $prop ? $prop . "\n" : '';
128128
foreach ($node as $sub) {
129-
$res .= rtrim(exportAST($sub), "\n") . "\n";
129+
if ($sub !== null) {
130+
$res .= rtrim(exportAST($sub), "\n") . "\n";
131+
}
130132
}
131133

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

0 commit comments

Comments
 (0)