Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/liquid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module Liquid
require 'liquid/parser'
require 'liquid/i18n'
require 'liquid/drop'
require 'liquid/self_drop'
require 'liquid/tablerowloop_drop'
require 'liquid/forloop_drop'
require 'liquid/extensions'
Expand Down
4 changes: 0 additions & 4 deletions lib/liquid/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ def find_variable(key, raise_on_not_found: true)
# path and find_index() is optimized in MRI to reduce object allocation
index = @scopes.find_index { |s| s.key?(key) }

# `self` resolves to a SelfDrop (enabling `self['var']` lookups),
# but only when it hasn't been explicitly assigned as a local variable.
return SelfDrop.new(self) if key == Expression::SELF && !index

variable = if index
lookup_and_evaluate(@scopes[index], key, raise_on_not_found: raise_on_not_found)
else
Expand Down
2 changes: 0 additions & 2 deletions lib/liquid/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module Liquid
class Expression
SELF = 'self'

LITERALS = {
nil => nil,
'nil' => nil,
Expand Down
38 changes: 0 additions & 38 deletions lib/liquid/self_drop.rb

This file was deleted.

17 changes: 11 additions & 6 deletions lib/liquid/variable_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ def evaluate(context)
res = context.lookup_and_evaluate(object, key)
object = res.to_liquid

# Some special cases. If the part wasn't in square brackets and
# no key with the same name was found we interpret following calls
# as commands and call them on the current object
# If "self" is not in scope or `self[key]` does not exist, try to
# resolve `key` in the current scope.
elsif i == 0 && name == "self" && key.is_a?(String) && context.variable_defined?(key)
object = context.find_variable(key)

# Some special cases. If the part wasn't in square brackets and
# no key with the same name was found we interpret following calls
# as commands and call them on the current object
elsif lookup_command?(i) && object.respond_to?(key)
object = object.send(key).to_liquid

Expand All @@ -75,9 +80,9 @@ def evaluate(context)
elsif lookup_command?(i) && object.is_a?(String) && (key == "first" || key == "last")
object = key == "first" ? (object[0] || "") : (object[-1] || "")

# No key was present with the desired value and it wasn't one of the directly supported
# keywords either. The only thing we got left is to return nil or
# raise an exception if `strict_variables` option is set to true
# No key was present with the desired value and it wasn't one of the directly supported
# keywords either. The only thing we got left is to return nil or
# raise an exception if `strict_variables` option is set to true
else
return nil unless context.strict_variables
raise Liquid::UndefinedVariable, "undefined variable #{key}"
Expand Down
Loading