mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 07:05:12 -07:00
Let environment self shadow SelfDrop
This commit is contained in:
committed by
Ian Ker-Seymer
parent
7b368dffb8
commit
529800f46b
@@ -206,16 +206,21 @@ module Liquid
|
|||||||
# path and find_index() is optimized in MRI to reduce object allocation
|
# path and find_index() is optimized in MRI to reduce object allocation
|
||||||
index = @scopes.find_index { |s| s.key?(key) }
|
index = @scopes.find_index { |s| s.key?(key) }
|
||||||
|
|
||||||
# `self` resolves to a SelfDrop (enabling `self['var']` lookups),
|
fallback_to_self_drop = key == Expression::SELF && index.nil?
|
||||||
# but only when it hasn't been explicitly assigned as a local variable.
|
|
||||||
return @self_drop ||= SelfDrop.new(self) if key == Expression::SELF && !index
|
|
||||||
|
|
||||||
variable = if index
|
variable = if index
|
||||||
lookup_and_evaluate(@scopes[index], key, raise_on_not_found: raise_on_not_found)
|
lookup_and_evaluate(@scopes[index], key, raise_on_not_found: raise_on_not_found)
|
||||||
else
|
else
|
||||||
try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found)
|
try_variable_find_in_environments(
|
||||||
|
key,
|
||||||
|
raise_on_not_found: raise_on_not_found && !fallback_to_self_drop,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# `self` resolves to a SelfDrop (enabling `self['var']` lookups),
|
||||||
|
# but only after the normal environment lookup doesn't find a value.
|
||||||
|
return @self_drop ||= SelfDrop.new(self) if fallback_to_self_drop && variable.nil?
|
||||||
|
|
||||||
# update variable's context before invoking #to_liquid
|
# update variable's context before invoking #to_liquid
|
||||||
variable.context = self if variable.respond_to?(:context=)
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user