-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow empty
to behave like an empty array (change needed in liquid-c)
#1084
base: main
Are you sure you want to change the base?
Conversation
@er1 This looks like a breaking-change to me. Can you test if the empty array can be filled later on..?
|
@ashmaroli It would depend on how that filter works. I am assuming that values are immutable and that the standard filters coerce to arrays when they need arrays before performing operations. This would be in line with how enumerable drops behave. |
e145273
to
f3d17c8
Compare
def test_empty_can_be_filled | ||
template = Template.parse("{% assign foo = empty %}{{ foo | concat: bar }}") | ||
assert_equal('Y', template.render!('bar' => ['Y'])) | ||
template = Template.parse("{% assign foo = empty %}{{ foo | concat: bar | join: '--' }}") | ||
assert_equal('A--B', template.render!('bar' => ['A', 'B'])) | ||
template = Template.parse("{% assign foo = empty %}{% assign tar = foo | concat: bar %}{{ tar | join: '--' }}{{ tar | size }}") | ||
assert_equal('A--B2', template.render!('bar' => ['A', 'B'])) | ||
end |
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.
@ashmaroli would using the concat filter here be enough to check if arrays from the empty literal can be filled?
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.
Yes, that is sufficient.
@er1 IMO, |
|
I see. Thanks for the feedback. |
failing tests in df49715 depend on Shopify/liquid-c#131 |
empty
to behave like an empty array (change needed in liquid-c)
This allows the
empty
literal to act as an empty array when being used outside of comparisons.It would make empty array constructions such as
{% assign x = '' | split: '' %}
more readable as{% assign x = empty %}
This should not impact existing uses since empty array will get coerced into empty string if and where it is being used.
Some tests are failing and depend on: Shopify/liquid-c#131