phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
62 stars 3 forks source link

Incomplete interpolation does not trigger error #70

Closed char101 closed 4 years ago

char101 commented 4 years ago

Hello,

I encountered an issue with the following code:

p.
  a #[a(href='') 
  b] c

I expected to get:

index.pug:2:18
    1| p.
  > 2|   a #[a(href='') 
------------------------^
    3|   b] c

End of line was reached with no closing bracket for interpolation.

But I actually get:

<p>a <a href=""></a><b></b> c
</p>

Thanks!

kylekatarnls commented 4 years ago

Indeed, pugjs is right to disallow new lines inside interpolation, as it would be very unsafe to use them.

kylekatarnls commented 4 years ago

Pugjs disallow interpolations #{} and tag interpolations #[] the same way. But multi-line interpolation can be a convenient feature for expressions:

- var foo = [9, 5];

p.
  start #{foo.reduce(function (i, n) {
    return i + n;
  }, 7)} end

Disallowing this would be a breaking change as some users could legitimately think this was allowed.

This means (at least for the expression part), this could be kept as is or should be an opt-in.

kylekatarnls commented 4 years ago

With the version 1.8.0: