Skip to content

Commit bdc9490

Browse files
committed
Test simplification (probably don't keep)
1 parent 4d134d5 commit bdc9490

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

‎src/HelperOptions.php‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class HelperOptions
1919
* @param array<mixed> $outerBlockParams outer block param stack, passed as trailing elements of the stack
2020
*/
2121
public function __construct(
22-
public mixed &$scope,
22+
public mixed $scope,
2323
public array &$data,
24+
private readonly RuntimeContext $cx,
2425
public readonly string $name = '',
2526
public readonly array $hash = [],
2627
public readonly int $blockParams = 0,
27-
private readonly ?RuntimeContext $cx = null,
2828
private readonly ?Closure $cb = null,
2929
private readonly ?Closure $inv = null,
3030
private readonly array $outerBlockParams = [],
@@ -45,9 +45,7 @@ public function __isset(string $name): bool
4545

4646
public function fn(mixed $context = Scope::Use, mixed $data = null): string
4747
{
48-
if ($this->cx === null) {
49-
throw new \Exception('fn() is not supported for inline helpers');
50-
} elseif ($this->cb === null) {
48+
if ($this->cb === null) {
5149
return '';
5250
}
5351
$cx = $this->cx;
@@ -87,9 +85,7 @@ public function fn(mixed $context = Scope::Use, mixed $data = null): string
8785

8886
public function inverse(mixed $context = null, mixed $data = null): string
8987
{
90-
if ($this->cx === null) {
91-
throw new \Exception('inverse() is not supported for inline helpers');
92-
} elseif ($this->inv === null) {
88+
if ($this->inv === null) {
9389
return '';
9490
}
9591
$cx = $this->cx;
@@ -134,7 +130,6 @@ public function iterate(array $items): string
134130
return '';
135131
}
136132
$cx = $this->cx;
137-
assert($cx !== null);
138133
$cb = $this->cb;
139134

140135
// Push depths and save partials once for the entire loop.
@@ -181,7 +176,6 @@ public function iterate(array $items): string
181176
private function applyData(array $data): array
182177
{
183178
$cx = $this->cx;
184-
assert($cx !== null);
185179
$savedFrame = null;
186180
$bpStack = null;
187181

‎src/Runtime.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ public static function hbch(RuntimeContext $cx, \Closure $helper, string $name,
521521
$positional[] = new HelperOptions(
522522
scope: $_this,
523523
data: $cx->frame,
524+
cx: $cx,
524525
name: $name,
525526
hash: $hash,
526527
);
@@ -544,10 +545,10 @@ public static function hbbch(RuntimeContext $cx, \Closure $helper, string $name,
544545
$positional[] = new HelperOptions(
545546
scope: $_this,
546547
data: $cx->frame,
548+
cx: $cx,
547549
name: $name,
548550
hash: $hash,
549551
blockParams: $blockParamCount,
550-
cx: $cx,
551552
cb: $cb,
552553
inv: $else,
553554
outerBlockParams: $outerBlockParams,

‎tests/RegressionTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ public static function issueProvider(): array
11081108
'template' => '{{foo}}{{bar}}',
11091109
'helpers' => [
11101110
'foo' => function (HelperOptions $opt) {
1111-
$opt->scope['change'] = true;
1111+
$opt->data['root']['change'] = true;
11121112
},
11131113
'bar' => fn(HelperOptions $opt) => $opt->scope['change'] ? 'ok' : 'bad',
11141114
],

0 commit comments

Comments
 (0)