Skip to content

Conversation

@charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Dec 3, 2025

Features

  • Add support for boolean expressions everywhere
    • As variable output {{ a or b }}
    • As filter argument {{ collection | where: 'prop', a or b }}
    • As tag argument {% render 'snip', enabled: a or b %}
    • As conditional tag argument {% if cond %} (extending previous behaviour)
  • Add support for subexpression prioritization and associativity
    • In ascending order of priority:
      • Logical: and, or (right to left)
      • Equality: ==, !=, <> (left to right)
      • Comparison: >, >=, <, <=, contains (left to right)
      • Groupings: ( expr )
    • For example, this is now supported
      • {{ a > b == c < d or e == f }} which is equivalent to
      • {{ ((a > b) == (c < d)) or (e == f) }}
  • Add support for parenthesized expressions
    • e.g. (a or b) == c

Notable passing test

  def test_assign_boolean_expression_assignment
    assert_template_result(
      'it rendered',
      <<~LIQUID,
        {%- assign should_render = a == 0 or (b == 1 and c == 2) -%}
        {%- if should_render -%}
          it rendered
        {%- endif -%}
      LIQUID
      { 'b' => 1, 'c' => 2 },
    )
  end

@charlespwd charlespwd force-pushed the cp-boolean-expressions branch from 6d4debe to f49de89 Compare December 4, 2025 19:38
Instead of having Condition parse the left op right, make
BinaryExpression do it. Make sure all the tests pass as they
used to in the process.
It was incompatible with the lexer anyway. Not used internally either.
@charlespwd charlespwd force-pushed the cp-boolean-expressions branch from 362d58e to 9f91128 Compare December 4, 2025 21:38
- Remove comparison expression logic
- Remove Condition#child_relation
- Remove Condition#and
- Remove Condition#or
- Simplify Condition#evaluate

This logic was moved to the Parser & BinaryExpression
@charlespwd charlespwd force-pushed the cp-boolean-expressions branch 2 times, most recently from 2b299cc to 9b26c86 Compare December 5, 2025 14:43
@charlespwd charlespwd force-pushed the cp-boolean-expressions branch from f62b920 to a33443c Compare December 5, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant