mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -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)
|
if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate)
|
||||||
new(start_obj, end_obj)
|
new(start_obj, end_obj)
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,24 +31,11 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(context)
|
def evaluate(context)
|
||||||
start_int = to_integer(context.evaluate(@start_obj))
|
start_int = RangeLookup.to_integer(context.evaluate(@start_obj))
|
||||||
end_int = to_integer(context.evaluate(@end_obj))
|
end_int = RangeLookup.to_integer(context.evaluate(@end_obj))
|
||||||
start_int..end_int
|
start_int..end_int
|
||||||
end
|
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
|
class ParseTreeVisitor < Liquid::ParseTreeVisitor
|
||||||
def children
|
def children
|
||||||
[@node.start_obj, @node.end_obj]
|
[@node.start_obj, @node.end_obj]
|
||||||
|
|||||||
Reference in New Issue
Block a user