twig.js
twig.js copied to clipboard
equality should evaluate to 1/0 not true/false
In twig, {% set x = 'y' %}{{x == 'y'}}
outputs "1"*; in twig.js it outputs "true". Conflating truthiness with the associated integer values seems like a bad habit but, if you do, this difference will quickly lead to trouble.
In twig, this outputs "2"; twig.js outputs "NaN":
{% set x = 'y' %}
{% set m = (x == 'y') %}
{# in twig, m now equals 1; in twig.js m now equals 'true' #}
{% set m = m + 1 %}
{{m}}
* note that a bare {{ x == 'y' }}
has no output in twig or twig.js
Its a little odd, because in JS:
> true+1
< 2
so we have the concept of adding Numbers to booleans (although this seems insane to me but never mind).
I can't fault your reasoning, we should be aiming for parity with twig PHP, but I've never understood why PHP converts booleans to integers when printing them. Oh well.