tyler-sommer/stick

Test inside a ternary expression breaks parsing

mjomble opened this issue · 2 comments

A template like this: {{ x is defined ? 1 : 0 }}
results in parse: expected "PRINT_CLOSE", got "PUNCTUATION"

Similarly, this {% set y = x is defined ? 1 : 0 %}
results in parse: expected "TAG_CLOSE", got "PUNCTUATION"

PS. There's a chance I'll find the time and motivation to fix this (and other such issues I may run into), so any tips or pointers about the codebase would be welcome 😄

I managed to look into this a bit.

parseExpr has two steps: parseInnerExpr and parseOuterExpr.

In the {{ x is defined ? 1 : 0 }} example, the inner expression is x and the outer expression is x is defined, but what we need is to go one step further and find the "outer outer" expression x is defined ? 1 : 0.

There are lots of different ways to approach this. @tyler-sommer do you have recommendations?

PS. A workaround is to change the template like this: {{ (x is defined) ? 1 : 0 }}.