-
Notifications
You must be signed in to change notification settings - Fork 14
Allow at most 2 unclosed nodes of the same type (open/open or close/close) in Liquid branches #186
Conversation
6955483
to
dea407d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @charlespwd! Awesome stuff! I've left only two minor suggestions/questions.
|
||
// 2 nodes but with children = not ok | ||
testCases = [ | ||
'{% if cond %}<a>hi</a><b>{% endif %}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, as a parser user, I find this scenario a bit unexpected:
👍 the parser doesn't throw any error:
{% if cond %}<b>{% endif %}
👎 the parser throws a LiquidHTMLParsingError: Attempting to close LiquidTag \'if\' before HtmlElement \'b\' was closed
error
{% if cond %}<a>hi</a><b>{% endif %}
As the a
gets successfully closed, it doesn't seem like it should implies in a side effect on b
.
(still, please, feel free to ignore if our goal is handling this is a different PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the fine line I'm trying to navigate. I'm trying to do this:
- Report problems when there might be one
- Don't report problems for something that is intentional
The strategy I went with was if there's two open or two close dangling markers, then it's intentional and we allow it.
<a>hi</a><b>
seems unintentional. Either you forgot the <b>
there or it should have been closed. Not so much with <a><b>
.
|
||
It should pretty print dangling close tags inside unless statements | ||
printWidth: 1 | ||
{% unless condition %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome we're covering unless
as well :)
I wonder if we could include include test cases with the tags for
, tablerow
, and form
as well (to document how we're handling blocks with those tags). Wdyt?
In this PR
Rationale
#90 has been opened for a while. A lot of folks intentionally add unclosed nodes inside Liquid if statements. This PR allows this to happen while still throwing errors for the cases that should be errors.
That is, we're being slightly more lenient with what we allow to be parsed as a "full tree."
Heuristic used
The logic used is as follows:
👍 Now allowed:
👎 Still recognized as error:
Style choice
I decided to treat the unclosed nodes the same way we treat nodes that do not have a closing tag (e.g.
<img>
). That is, we won't mess with the indentation in reaction to them.Consequences:
Which feels awkward as hell, but tbh it already was 😅
Reasoning:
If someone does something funky like the above, but there's also an if branch with only one child, deciding which indentation of the siblings should have would get wonky real fast.
Fixes #90