Skip to content

Commit 07b4c2d

Browse files
committed
Improve runtime method naming
1 parent 80a6b95 commit 07b4c2d

2 files changed

Lines changed: 65 additions & 64 deletions

File tree

src/Compiler.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private function BlockStatement(BlockStatement $block): string
196196

197197
$nameArg = !$this->context->options->knownHelpersOnly && (!$inverted || $type === SexprType::Ambiguous) ? ", $escapedName" : ', null';
198198
$outerBpArg = $this->blockParamValues ? ', $blockParams' : '';
199-
return self::getRuntimeFunc('sec', "\$cx, $var, \$in, $fn, $else$nameArg$outerBpArg");
199+
return self::getRuntimeFunc('section', "\$cx, $var, \$in, $fn, $else$nameArg$outerBpArg");
200200
}
201201

202202
private function isKnownHelper(string $helperName): bool
@@ -331,7 +331,7 @@ private function canInlineConditional(BlockStatement $block, string $helperName,
331331

332332
/**
333333
* Compile the condition expression for an inlined if/unless ternary.
334-
* Single-segment plain context paths (e.g. {{#if foo}}) use cv() so that closures are
334+
* Single-segment plain context paths (e.g. {{#if foo}}) use lookupValue() so that closures are
335335
* invoked before being tested. All other expressions (multi-segment paths, data variables,
336336
* block params, sub-expressions) use compileExpression() as a helper argument.
337337
* Closures at nested path segments are not invoked.
@@ -345,17 +345,17 @@ private function compileConditionalExpr(Expression $condExpr, bool $negate): str
345345
&& is_string($part)
346346
&& count($condExpr->parts) === 1;
347347
if ($isSimplePath && $condExpr->data) {
348-
$val = self::getRuntimeFunc('dv', $this->compileExpression($condExpr));
348+
$val = self::getRuntimeFunc('lambda', $this->compileExpression($condExpr));
349349
} elseif ($isSimplePath && !self::scopedId($condExpr) && $this->lookupBlockParam($part) === null) {
350-
$val = self::getRuntimeFunc('cv', '$in, ' . self::quote($part));
350+
$val = self::getRuntimeFunc('lookupValue', '$in, ' . self::quote($part));
351351
} else {
352352
$savedHelperArgs = $this->compilingHelperArgs;
353353
$this->compilingHelperArgs = true;
354354
$val = $this->compileExpression($condExpr);
355355
$this->compilingHelperArgs = $savedHelperArgs;
356356
}
357-
$cond = self::getRuntimeFunc('ifvar', $val);
358-
return $negate ? "!$cond" : $cond;
357+
$isEmpty = self::getRuntimeFunc('isEmpty', $val);
358+
return $negate ? $isEmpty : "!$isEmpty";
359359
}
360360

361361
private function compileDynamicBlockHelper(BlockStatement $block, string $name, string $varPath): string
@@ -389,13 +389,13 @@ private function DecoratorBlock(BlockStatement $block): string
389389
$body = $this->compileProgramOrEmpty($block->program);
390390

391391
// Register in usedPartial so {{> partialName}} can compile without error.
392-
// Do NOT add to partialCode - `in()` handles runtime registration, keeping inline partials block-scoped.
392+
// Do NOT add to partialCode - setInlinePartial() handles runtime registration, keeping inline partials block-scoped.
393393
$this->context->usedPartial[$partialName] = '';
394394

395395
// Capture $blockParams and any hoisted program vars so the inline partial body can access them.
396396
$useVars = $this->buildInlineUseClause($depsBefore);
397397
$escapedName = self::quote($partialName);
398-
return self::getRuntimeFunc('in', "\$cx, $escapedName, " . self::templateClosure($body, useVars: $useVars));
398+
return self::getRuntimeFunc('setInlinePartial', "\$cx, $escapedName, " . self::templateClosure($body, useVars: $useVars));
399399
}
400400

401401
private function Decorator(Decorator $decorator): never
@@ -434,7 +434,7 @@ private function PartialStatement(PartialStatement $statement): string
434434
// In compat mode, pass the caller's $in so the partial inherits the full context chain.
435435
$compatArg = $this->context->options->compat ? ', null, $in' : '';
436436

437-
return $prepend . self::getRuntimeFunc('p', "\$cx, $p, $vars, $indent$compatArg");
437+
return $prepend . self::getRuntimeFunc('invokePartial', "\$cx, $p, $vars, $indent$compatArg");
438438
}
439439

440440
private function PartialBlockStatement(PartialBlockStatement $statement): string
@@ -484,16 +484,16 @@ private function PartialBlockStatement(PartialBlockStatement $statement): string
484484
if ($partialName !== null && !$found) {
485485
// Register the block body as a fallback partial only if no runtime partial with this name exists yet.
486486
$parts[] = "(isset(\$cx->inlinePartials[$p]) || isset(\$cx->partials[$p]) ? '' : "
487-
. self::getRuntimeFunc('in', "\$cx, $p, $bodyClosure") . ')';
487+
. self::getRuntimeFunc('setInlinePartial', "\$cx, $p, $bodyClosure") . ')';
488488
}
489489
$compatArg = $this->context->options->compat ? ', $in' : '';
490-
$parts[] = self::getRuntimeFunc('p', "\$cx, $p, $vars, '', $bodyClosure$compatArg");
490+
$parts[] = self::getRuntimeFunc('invokePartial', "\$cx, $p, $vars, '', $bodyClosure$compatArg");
491491
return implode('.', $parts);
492492
}
493493

494494
private function MustacheStatement(MustacheStatement $mustache): string
495495
{
496-
$fn = (!$mustache->escaped || $this->context->options->noEscape) ? 'raw' : 'encq';
496+
$fn = (!$mustache->escaped || $this->context->options->noEscape) ? 'raw' : 'escapeExpression';
497497
$path = $mustache->path;
498498

499499
// SubExpression path: {{(path args)}} — always a direct helper call result
@@ -520,18 +520,18 @@ private function MustacheStatement(MustacheStatement $mustache): string
520520
$strict = $this->context->options->strict ? 'true' : 'false';
521521
// @data vars are never depth-walked in compat mode.
522522
$compat = ($this->context->options->compat && !$isData) ? 'true' : 'false';
523-
return self::getRuntimeFunc($fn, self::getRuntimeFunc('hv', "\$cx, $escapedKey, $scope, $assumeObjects, $strict, $compat"));
523+
return self::getRuntimeFunc($fn, self::getRuntimeFunc('invokeAmbiguous', "\$cx, $escapedKey, $scope, $assumeObjects, $strict, $compat"));
524524
}
525525

526526
// Simple: direct path lookup with lambda resolution.
527-
// For knownHelpersOnly bare identifiers (single-segment, non-data): use cv() to pass the
527+
// For knownHelpersOnly bare identifiers (single-segment, non-data): use lookupValue() to pass the
528528
// current context to any Closure, mirroring JS fn.call(context) where context is `this`.
529-
// For all other simple paths (multi-segment, scoped, depth, data): use dv() with zero args,
529+
// For all other simple paths (multi-segment, scoped, depth, data): use lambda() with zero args,
530530
// matching HBS.js container.lambda which also passes no positional arguments.
531531
if ($path instanceof PathExpression) {
532532
if ($helperName !== null && !$path->data && $this->context->options->knownHelpersOnly && !$this->context->options->compat) {
533533
$cvArgs = '$in, ' . self::quote($helperName) . ($this->context->options->strict ? ', true' : '');
534-
return self::getRuntimeFunc($fn, self::getRuntimeFunc('cv', $cvArgs));
534+
return self::getRuntimeFunc($fn, self::getRuntimeFunc('lookupValue', $cvArgs));
535535
}
536536
$expression = $this->PathExpression($path);
537537
} else {
@@ -540,7 +540,7 @@ private function MustacheStatement(MustacheStatement $mustache): string
540540
$expression = $this->compileModeAwareLookup('$in', [$literalKey], $literalKey);
541541
}
542542

543-
return self::getRuntimeFunc($fn, self::getRuntimeFunc('dv', $expression));
543+
return self::getRuntimeFunc($fn, self::getRuntimeFunc('lambda', $expression));
544544
}
545545

546546
// ── Expressions ─────────────────────────────────────────────────
@@ -654,7 +654,7 @@ private function Hash(Hash $hash): string
654654
private function resolveAndCompilePartial(string $name): void
655655
{
656656
if (isset($this->context->usedPartial[$name]) || str_starts_with($name, '@partial-block')) {
657-
// @partial-block is resolved at runtime via in()/p()
657+
// @partial-block is resolved at runtime via setInlinePartial()/invokePartial()
658658
return;
659659
}
660660

@@ -842,7 +842,7 @@ private function buildBlockHelperCall(string $helperExpr, string $escapedName, B
842842
// omit trailing bpCount/outerBp args when both are zero/empty
843843
$trailingArgs = ($bpCount > 0 || $outerBp !== '[]') ? ", $outerBp, $bpCount" : '';
844844
$args = "\$cx, $helperExpr, $escapedName, $params, \$in, $fn, $else";
845-
return self::getRuntimeFunc('hbbch', $args . $trailingArgs);
845+
return self::getRuntimeFunc('invokeBlockHelper', $args . $trailingArgs);
846846
}
847847

848848
/**
@@ -857,7 +857,7 @@ private function compileHelperCall(?string $helperName, Expression $path, array
857857
$escapedName = self::quote($helperName);
858858
$isData = $path instanceof PathExpression && $path->data;
859859
if ($this->isKnownHelper($helperName)) {
860-
return self::getRuntimeFunc('hbch', "\$cx, \$cx->helpers[$escapedName], $escapedName, $compiledParams, \$in");
860+
return self::getRuntimeFunc('invokeHelper', "\$cx, \$cx->helpers[$escapedName], $escapedName, $compiledParams, \$in");
861861
}
862862
if ($this->context->options->knownHelpersOnly) {
863863
$this->throwKnownHelpersOnly($helperName);
@@ -882,7 +882,7 @@ private function compileHelperCall(?string $helperName, Expression $path, array
882882
}
883883

884884
$resolved = self::getRuntimeFunc('resolveHelper', "\$cx, $escapedName, $varPath, $checkHelpers");
885-
return self::getRuntimeFunc('hbch', "\$cx, $resolved, $escapedName, $compiledParams, \$in");
885+
return self::getRuntimeFunc('invokeHelper', "\$cx, $resolved, $escapedName, $compiledParams, \$in");
886886
}
887887

888888
/**

0 commit comments

Comments
 (0)