Shopify / prettier-plugin-liquid

Prettier Liquid/HTML plugin
https://npm.im/@shopify/prettier-plugin-liquid
MIT License
93 stars 15 forks source link

Fixup parsing of `{% else-%}` #129

Closed charlespwd closed 1 year ago

charlespwd commented 1 year ago

This is a weird parsing ambiguity problem.

Before, our rule was the following:

identifierCharacter = alnum | "_" | "-"
liquidTagBaseCase = "{%" space* (tagName ~identifierCharacter) space* tagMarkup "-"? "%}"

Our problem was that - is both an identifier character and the character we use for stripping whitespace from the end of tags and variable output (-%} and -}}).

So {% else-%} threw an error because tagName was followed by -, which is an identifier character.

The solution is to change that rule to the following:

Fixes #126