mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Fixup parsing of range lookup for weird types
Had a NoMethodError bubble up in the theme-check-language-server because of a unit test I ran for the prettier plugin. (true..false) was crashing. We have a helper... right there for this. So I used it here to turn the error into an ArgumentError instead. Which should get caught
This commit is contained in:
+14
-16
@@ -8,7 +8,18 @@ module Liquid
|
||||
if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate)
|
||||
new(start_obj, end_obj)
|
||||
else
|
||||
start_obj.to_i..end_obj.to_i
|
||||
to_integer(start_obj)..to_integer(end_obj)
|
||||
end
|
||||
end
|
||||
|
||||
def self.to_integer(input)
|
||||
case input
|
||||
when Integer
|
||||
input
|
||||
when NilClass, String
|
||||
input.to_i
|
||||
else
|
||||
Utils.to_integer(input)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,24 +31,11 @@ module Liquid
|
||||
end
|
||||
|
||||
def evaluate(context)
|
||||
start_int = to_integer(context.evaluate(@start_obj))
|
||||
end_int = to_integer(context.evaluate(@end_obj))
|
||||
start_int = RangeLookup.to_integer(context.evaluate(@start_obj))
|
||||
end_int = RangeLookup.to_integer(context.evaluate(@end_obj))
|
||||
start_int..end_int
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def to_integer(input)
|
||||
case input
|
||||
when Integer
|
||||
input
|
||||
when NilClass, String
|
||||
input.to_i
|
||||
else
|
||||
Utils.to_integer(input)
|
||||
end
|
||||
end
|
||||
|
||||
class ParseTreeVisitor < Liquid::ParseTreeVisitor
|
||||
def children
|
||||
[@node.start_obj, @node.end_obj]
|
||||
|
||||
Reference in New Issue
Block a user