latte-tools icon indicating copy to clipboard operation
latte-tools copied to clipboard

Twiggy compiler fixes

Open jcheron opened this issue 2 years ago • 0 comments

  • [x] bug fix : no open issue
  • [ ] BC break

Fixed:

These behaviors may have been voluntary choices... I don't know

raw filter

Twig raw filter is not interpreted.

Twig Expected Latte Actual Latte
{{foo|raw}} {$foo|noescape} {$foo}

see https://github.com/nette/latte-tools/commit/7aaba40e857642c503979e9b288b1d376cdea069

Twig array access

Access to the element of a Twig array is transformed into access to the member of an object.

Twig Expected Latte Actual Latte
{{bar['foo']}} {$bar['foo']} {$bar->foo}

see https://github.com/nette/latte-tools/commit/209d1fb0733902ef46b2de6f537be8962aac576a

Twig and Twiggy coexisting

pb with Twig already installed in a project (cannot redeclare Twig global functions...)

  • checks with function_exists the previous declaration of the Twig global functions, see https://github.com/nette/latte-tools/commit/c1a06ed93e152dda03c61cfeda9e48480667ca72

_self replacement with toString

Replacing {{_self}} with {$_self} is problematic:

  • _self with Twig refers to the template instance, using it alone in an expression calls the toString which displays the template name.
  • $_self is not defined with Latte
Twig Expected Latte Actual Latte
{{_self}} {$this->getName()} {$_self}

see https://github.com/nette/latte-tools/commit/5250d9c7055531846f59058f87e1d268e0b66e0e

Unit tests

The unit tests have been modified accordingly: see https://github.com/nette/latte-tools/commit/4a2e2f5d0ae7e64af505cdedf3ce9a87f340dbc6

jcheron avatar Jan 16 '23 13:01 jcheron