99use DevTheorem \HandlebarsParser \Ast \Decorator ;
1010use DevTheorem \HandlebarsParser \Ast \Expression as AstExpression ;
1111use DevTheorem \HandlebarsParser \Ast \Hash ;
12+ use DevTheorem \HandlebarsParser \Ast \Literal ;
1213use DevTheorem \HandlebarsParser \Ast \MustacheStatement ;
1314use DevTheorem \HandlebarsParser \Ast \Node ;
1415use DevTheorem \HandlebarsParser \Ast \NullLiteral ;
2728final class NewCompiler
2829{
2930 private int $ partialBlockId = 0 ;
31+ private Context $ context ;
32+ private Options $ options ;
3033
3134 /**
3235 * @param list<array<string>> $blockParamValues
33- * @param list<Node> $sourceNode
3436 */
3537 public function __construct (
3638 private array $ blockParamValues = [],
37- private array $ sourceNode = [],
38- private Options $ options = new Options (),
3939 ) {}
4040
41- public function compile (Program $ program , Options $ options ): string
41+ public function compile (Program $ program , Context $ context ): string
4242 {
4343 $ this ->blockParamValues = [];
44- $ this ->sourceNode = [] ;
45- $ this ->options = $ options ;
44+ $ this ->context = $ context ;
45+ $ this ->options = $ context -> options ;
4646 $ this ->partialBlockId = 0 ;
4747
4848 array_unshift ($ this ->blockParamValues , $ program ->blockParams );
@@ -241,6 +241,7 @@ private function compileBlockHelper(BlockStatement $block, string $helperName):
241241 }
242242
243243 $ params = $ this ->compileParams ($ block ->params , $ block ->hash , $ bp ?: null );
244+ $ this ->context ->usedHelpers [$ helperName ] = true ;
244245
245246 if ($ inverted ) {
246247 $ body = $ block ->inverse ? $ this ->compileProgram ($ block ->inverse ) : "'' " ;
@@ -257,7 +258,12 @@ private function compileBlockHelper(BlockStatement $block, string $helperName):
257258
258259 private function DecoratorBlock (): string
259260 {
260- return '' ;
261+ return '' ; // todo: throw?
262+ }
263+
264+ private function Decorator (Decorator $ decorator ): string
265+ {
266+ return '' ; // todo: throw?
261267 }
262268
263269 private function PartialStatement (PartialStatement $ statement ): string
@@ -312,6 +318,7 @@ private function MustacheStatement(MustacheStatement $mustache): string
312318
313319 // Registered helper
314320 if ($ helperName !== null && isset ($ this ->options ->helpers [$ helperName ])) {
321+ $ this ->context ->usedHelpers [$ helperName ] = true ;
315322 $ params = $ this ->compileParams ($ mustache ->params , $ mustache ->hash );
316323 $ call = "LR::hbch( \$cx, ' $ helperName', $ params, \$in) " ;
317324 return "'. " . $ this ->getFuncName ($ fn , $ call ) . ").' " ;
@@ -337,11 +344,6 @@ private function MustacheStatement(MustacheStatement $mustache): string
337344 return "'. " . $ this ->getFuncName ($ fn , $ val ) . ").' " ;
338345 }
339346
340- private function Decorator (Decorator $ decorator ): string
341- {
342- return '' ;
343- }
344-
345347 private function ContentStatement (ContentStatement $ statement ): string
346348 {
347349 return addcslashes ($ statement ->value , "' \\" );
@@ -365,6 +367,7 @@ private function SubExpression(SubExpression $expression): string
365367
366368 // Registered helper
367369 if ($ helperName !== null && isset ($ this ->options ->helpers [$ helperName ])) {
370+ $ this ->context ->usedHelpers [$ helperName ] = true ;
368371 $ params = $ this ->compileParams ($ expression ->params , $ expression ->hash );
369372 return "LR::hbch( \$cx, ' $ helperName', $ params, \$in) " ;
370373 }
@@ -376,6 +379,7 @@ private function SubExpression(SubExpression $expression): string
376379
377380 // Non-registered helper — still try as helper call
378381 if ($ helperName !== null ) {
382+ $ this ->context ->usedHelpers [$ helperName ] = true ;
379383 $ params = $ this ->compileParams ($ expression ->params , $ expression ->hash );
380384 return "LR::hbch( \$cx, ' $ helperName', $ params, \$in) " ;
381385 }
@@ -530,7 +534,7 @@ private function compilePartialParams(array $params, ?Hash $hash): string
530534 /**
531535 * Extract simple helper name from a path if it's a single-segment, non-data, depth-0 path.
532536 */
533- private function getSimpleHelperName (PathExpression |\ DevTheorem \ HandlebarsParser \ Ast \ Literal $ path ): ?string
537+ private function getSimpleHelperName (PathExpression |Literal $ path ): ?string
534538 {
535539 if (!$ path instanceof PathExpression) {
536540 return null ;
0 commit comments