Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

[BUG] Issue with conditional tags #144

Closed
blanklob opened this issue Sep 24, 2023 · 2 comments
Closed

[BUG] Issue with conditional tags #144

blanklob opened this issue Sep 24, 2023 · 2 comments

Comments

@blanklob
Copy link

Hey there I have an issue with conditional tags the vscode extension reports an error but theme check deosn't thanks, here is a loom about the issue.

https://www.loom.com/share/1471e9b27acf4ab6896e354699c9ffe8

@charlespwd
Copy link
Contributor

charlespwd commented Oct 17, 2023

Yeah so this is caused because we don't have a way to parse IF tags as HTML tag names.

Unfortunately, I don't have a fix for this because I believe it would make the syntax ambiguous. For the prettier plugin to work (and our LiquidHTML parser, which powers the next version of theme check), we kind of need to be slightly more specific about what we accept.

You have a couple of options:

  1. Dangling open/close nodes inside if statements are OK
{% if cond %}
  <some-wrapper with-some-props>
{% else %}
  <some-other-wrapper with-some-other-props>
{% endif %}

{% if cond %}
  </some-wrapper>
{% else %}
  </some-other-wrapper>
{% endif %}
  1. Name and props as variables
{% liquid
  if cond
    assign wrapper = 'some-wrapper'
    assign props = '...'
  else
    assign wrapper = 'some-other-wrapper'
    assign props = '...'
  endif
%}
<{{ wrapper }} {{ props }}>

</{{ wrapper }}>

Known issues that don't work:

<{% if cond %}wrapper props{% else %}other other-props{% endif %}>

</{% if cond %}wrapper{% else %}other{% endif %}>

Mostly because our LiquidHTML HTMLElement nodes are something like this type:

interface HTMLElement {
  name: (LiquidVariableOutput | TextNode)[]
  attributes: (HTMLAttribute | LiquidNode)[]
}

@blanklob
Copy link
Author

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants