liquidjs icon indicating copy to clipboard operation
liquidjs copied to clipboard

is {%else if foo %} valid syntax?

Open amit777 opened this issue 1 year ago • 4 comments
trafficstars

I noticed this liquid syntax is getting parsed correctly when it shouldn't (notice the space between else and if in else if invalid:

{% assign bar = "bar" -%}
{% if foo %}
FOO
{% else if invalid %}
THIS SHOULD NOT BE
{% else %}
ELSE
{% endif %}

It renders

THIS SHOULD NOT BE

ELSE

amit777 avatar Feb 07 '24 15:02 amit777

I would have expected the parser to throw an error with this template about the {% else if invalid %}

amit777 avatar Feb 07 '24 15:02 amit777

I drafted a PR that throws an error in the else if case, but I just noticed that Shopify isn't throwing an error in the same case. They just parse the 'invalid' else if... as an else and ignore following conditions: image

Should we be seeking to replicate the behaviour of the Ruby library here, or is throwing a parse error desired?

joel-hamilton avatar Feb 14 '24 02:02 joel-hamilton

Though we don't replicate many of error scenarios in Shopify, consistency is always good. I think we can leave it as it is, as it's already consistent with Shopify.

harttle avatar Feb 14 '24 02:02 harttle

Agreed that throwing an error isn't desired, I'll close the draft PR.

I think the real issue is that liquidjs is rendering multiple else blocks in the same conditional statement. I opened #670

joel-hamilton avatar Feb 16 '24 00:02 joel-hamilton