Skip to content

Arrow function helpers generate invalid php code #366

@thewunder

Description

@thewunder

The PHP Code:

require('./vendor/autoload.php');
use LightnCandy\LightnCandy;

// template doesn't matter
// Helpers:
$helpers = array(
  'formatInt' => fn($value) => number_format($value)
);

$phpStr = LightnCandy::compile($template, array(
  // Used compile flags
  'flags' => LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_HANDLEBARS,
  'helpers' => $helpers,
));
// Generated php code
use \LightnCandy\SafeString as SafeString;use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array(            'formatInt' =>             $hb->addHelper('formatInt', fn($value) => number_format($value));
    ,
);
/// etc...

Results: ParseError: syntax error, unexpected token ";", expecting ")" on line 2

The Issue:

Arrow functions as helpers generate invalid php code
Simply changing to a full closure fixes the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions