Skip to content

Commit deb361b

Browse files
committed
Simplify
1 parent 1c47d9c commit deb361b

2 files changed

Lines changed: 10 additions & 25 deletions

File tree

src/Compiler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,15 +889,14 @@ private function compileHelperCall(?string $helperName, Expression $path, array
889889
// All-string parts (foo.bar, ../fn, ./fn, @fn): scoped/depth/data paths resolve
890890
// from context only; normal paths check the helpers hash first via resolveHelper.
891891
$escapedName = self::quote($path->original);
892-
$resolverFn = (!$path->data && $path->depth === 0 && !self::scopedId($path))
893-
? 'resolveHelper'
894-
: 'resolveContextHelper';
892+
$checkHelpers = !$path->data && $path->depth === 0 && !self::scopedId($path);
895893
} else {
896894
// SubExpression-headed path (e.g. ((helper).prop args)): context-only resolution.
897895
$escapedName = self::quote(implode('.', $stringParts));
898-
$resolverFn = 'resolveContextHelper';
896+
$checkHelpers = false;
899897
}
900-
$resolved = self::getRuntimeFunc($resolverFn, "\$cx, $escapedName, $varPath");
898+
$extraArg = $checkHelpers ? '' : ", false";
899+
$resolved = self::getRuntimeFunc('resolveHelper', "\$cx, $escapedName, $varPath$extraArg");
901900
return self::getRuntimeFunc('hbch', "\$cx, $resolved, $escapedName, $compiledParams, \$in");
902901
}
903902

src/Runtime.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,14 @@ public static function in(RuntimeContext $cx, string $name, Closure $partial): s
423423
}
424424

425425
/**
426-
* Resolve a helper by name: check the helper registry, then the pre-resolved callable
427-
* (for pathed expressions), then the current context, then fall back to helperMissing.
428-
* Throws if a non-null, non-Closure value is found.
426+
* Resolve a helper by name: optionally check the helper registry, then the pre-resolved
427+
* callable, then fall back to helperMissing. Throws if a non-null, non-Closure value is found.
428+
* Pass $checkHelpers = false for scoped (./), depth (../), and data (@) paths, which resolve
429+
* from context only, matching HBS.js behaviour.
429430
*/
430-
public static function resolveHelper(RuntimeContext $cx, string $name, mixed $callable): Closure
431+
public static function resolveHelper(RuntimeContext $cx, string $name, mixed $callable, bool $checkHelpers = true): Closure
431432
{
432-
$helper = $cx->helpers[$name] ?? $callable ?? null;
433+
$helper = $checkHelpers ? ($cx->helpers[$name] ?? $callable) : $callable;
433434
if ($helper instanceof Closure) {
434435
return $helper;
435436
}
@@ -439,21 +440,6 @@ public static function resolveHelper(RuntimeContext $cx, string $name, mixed $ca
439440
return $cx->helpers['helperMissing'];
440441
}
441442

442-
/**
443-
* Like resolveHelper but skips the helpers hash lookup — for scoped (./), depth (../),
444-
* and data (@) paths which resolve from context only, matching HBS.js behaviour.
445-
*/
446-
public static function resolveContextHelper(RuntimeContext $cx, string $name, mixed $callable): Closure
447-
{
448-
if ($callable instanceof Closure) {
449-
return $callable;
450-
}
451-
if ($callable !== null) {
452-
throw new \Exception("Expected $name to be a function, got " . json_encode($callable));
453-
}
454-
return $cx->helpers['helperMissing'];
455-
}
456-
457443
/**
458444
* Invoke a resolved helper Closure with positional params, hash, and a HelperOptions instance.
459445
* Used for known helpers and resolved helpers (direct hbch calls from generated code),

0 commit comments

Comments
 (0)