Skip to content

Commit 67a203a

Browse files
committed
Fix parse error when using length with @root
zordius/lightncandy#370
1 parent 373f4aa commit 67a203a

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/Compiler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ protected static function getVariableName(Context $context, array $var, ?array $
199199
if ($levels > 0) {
200200
$checks[] = "isset($base)";
201201
}
202+
$p = count($var) ? Expression::arrayString($var) : '';
203+
if ($p !== '' && ($spvar || $levels === 0)) {
204+
$checks[] = "isset($base$p)";
205+
}
202206
if (!$spvar) {
203-
$p = count($var) ? Expression::arrayString($var) : '';
204-
if ($levels === 0 && $p !== '') {
205-
$checks[] = "isset($base$p)";
206-
}
207207
$checks[] = ("$base$p" == '$in') ? '$inary' : "is_array($base$p)";
208208
}
209209
$lenStart = '(' . ((count($checks) > 1) ? '(' : '') . implode(' && ', $checks) . ((count($checks) > 1) ? ')' : '') . " ? count($base" . Expression::arrayString($var) . ') : ';

tests/RegressionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,13 @@ public static function issueProvider(): array
13831383
'expected' => '<p class="empty">bar</p>',
13841384
],
13851385

1386+
[
1387+
'id' => 370,
1388+
'template' => '{{@root.items.length}}',
1389+
'data' => ['items' => [1, 2, 3]],
1390+
'expected' => '3',
1391+
],
1392+
13861393
[
13871394
'template' => '{{#each . as |v k|}}#{{k}}{{/each}}',
13881395
'data' => ['a' => [], 'c' => []],

0 commit comments

Comments
 (0)