Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Infix Operators in Liquid #1923

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Support for Infix Operators in Liquid #1923

wants to merge 1 commit into from

Conversation

albchu
Copy link

@albchu albchu commented Mar 4, 2025

Overview

This PR introduces a significant syntax improvement to Liquid templates:

Infix Operator Support: More intuitive mathematical and logical operations

This change makes templates more readable and concise by allowing developers to write expressions in a more natural way.

Changes

Infix Operator Support

  • Add arithmetic operators: +, -, *, /
  • Add comparison operators: >, >=, ==, <=, <
  • Add logical operators: &&, ||
  • Add XOR operator: ^
  • Support operator precedence and parenthesized expressions

Before:

{% assign media_count = media_count | minus: variant_images.size | plus: 1 %}

After:

{% assign media_count = media_count - variant_images.size + 1 %}

Benefits

  • More Readable Code: Expressions are written in a more natural and familiar syntax
  • Less Verbose: Fewer characters and more straightforward expressions
  • Easier Maintenance: Simpler syntax reduces cognitive load for developers
  • Familiar Syntax: Follows conventions from other programming languages

Testing

Added a new test suite:

  • infix_operators_unit_test.rb: Tests arithmetic, comparison, and logical operators

All tests should pass with the implementation.

@albchu
Copy link
Author

albchu commented Mar 4, 2025

Split this out from #1922 because the work is massively more complex than is feasible to prioritize at this time. These unit tests can still be useful when we return to this.

@albchu albchu changed the title Infix Operator Support Support for Infix Operators in Liquid Mar 4, 2025
@isaacbowen
Copy link

Liquid being postfix-y (with filter chaining and such), introducing infix feels as seismic as the Shopify Admin API going GraphQL.

This isn't good or bad, just a, uh, premonition. ;)

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

Successfully merging this pull request may close these issues.

2 participants