pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
387 stars 42 forks source link

Error with unescaped interpolation in mixin using JS expressionLanguage mode #117

Closed dadajuice closed 7 years ago

dadajuice commented 7 years ago

Hi,

I think I've encountered a bug using unescaped interpolation within a mixin. Here's the code I used (based on the example provided on PugJs website).

mixin test(data)
  =!{data}

.quote
  p Joel: !{"<em>Some of the girls are wearing my mother's clothing.</em>"}

+test("<em>Some of the girls are wearing my mother's clothing.</em>")

If I only use the unescaped interpolation normally it worked as expected, but if I use it within my test mixin it triggers an error :

Fatal error: Uncaught JsPhpize\Parser\Exception: Unexpected } in on line 1 near from data

I'm constructing the Pug instance with the following code :

$options = [
    'basedir' => ROOT_DIR . '/public',
    'expressionLanguage' => 'js',
    'upToDateCheck' => true
];
$pug = new Pug($options);
echo $pug->render("test.pug");

Thanks a lot!

kylekatarnls commented 7 years ago

Sorry but =!{data} is not valid nor in PugJS, neither in PugPHP, the following is valid on both:

mixin test(data)
  !=data

.quote
  p Joel: !{"<em>Some of the girls are wearing my mother's clothing.</em>"}

+test("<em>Some of the girls are wearing my mother's clothing.</em>")

Or:

mixin test(data)
  | !{data}

.quote
  p Joel: !{"<em>Some of the girls are wearing my mother's clothing.</em>"}

+test("<em>Some of the girls are wearing my mother's clothing.</em>")

But you cannot mix = that should be followed by a expression, and !{} that is available in raw texts (after |, after . and a new indented line or after a tag and a space)

dadajuice commented 7 years ago

Thanks a lot for the prompt response! It works perfectly!