Address comments

This commit is contained in:
Peter Zhu
2020-10-26 16:16:30 -04:00
parent 0bedc71854
commit 5c082472a1
5 changed files with 19 additions and 15 deletions
+4 -14
View File
@@ -11,7 +11,7 @@ module Liquid
def parse(tokens) def parse(tokens)
@body = new_body @body = new_body
while parse_body(@body, tokens, partial: true) while parse_body(@body, tokens)
end end
@body.freeze @body.freeze
end end
@@ -68,9 +68,7 @@ module Liquid
end end
# @api public # @api public
def parse_body(body, tokens, partial: false) def parse_body(body, tokens)
block_terminated = true
if parse_context.depth >= MAX_DEPTH if parse_context.depth >= MAX_DEPTH
raise StackLevelError, "Nesting too deep" raise StackLevelError, "Nesting too deep"
end end
@@ -79,10 +77,7 @@ module Liquid
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params| body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
@blank &&= body.blank? @blank &&= body.blank?
if end_tag_name == block_delimiter return false if end_tag_name == block_delimiter
block_terminated = false
next
end
raise_tag_never_closed(block_name) unless end_tag_name raise_tag_never_closed(block_name) unless end_tag_name
# this tag is not registered with the system # this tag is not registered with the system
@@ -93,12 +88,7 @@ module Liquid
parse_context.depth -= 1 parse_context.depth -= 1
end end
unless partial true
body.remove_blank_strings if body.blank?
body.freeze
end
block_terminated
end end
end end
end end
+1 -1
View File
@@ -199,7 +199,7 @@ module Liquid
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
raise "Can only render when frozen" unless frozen? freeze unless frozen?
context.resource_limits.increment_render_score(@nodelist.length) context.resource_limits.increment_render_score(@nodelist.length)
+4
View File
@@ -21,6 +21,10 @@ module Liquid
def parse(tokens) def parse(tokens)
body = new_body body = new_body
body = @blocks.last.attachment while parse_body(body, tokens) body = @blocks.last.attachment while parse_body(body, tokens)
if blank?
@blocks.each { |condition| condition.attachment.remove_blank_strings }
end
@blocks.each { |condition| condition.attachment.freeze }
end end
def nodelist def nodelist
+6
View File
@@ -62,6 +62,12 @@ module Liquid
if parse_body(@for_block, tokens) if parse_body(@for_block, tokens)
parse_body(@else_block, tokens) parse_body(@else_block, tokens)
end end
if blank?
@for_block.remove_blank_strings
@else_block&.remove_blank_strings
end
@for_block.freeze
@else_block&.freeze
end end
def nodelist def nodelist
+4
View File
@@ -31,6 +31,10 @@ module Liquid
def parse(tokens) def parse(tokens)
while parse_body(@blocks.last.attachment, tokens) while parse_body(@blocks.last.attachment, tokens)
end end
if blank?
@blocks.each { |condition| condition.attachment.remove_blank_strings }
end
@blocks.each { |block| block.attachment.freeze }
end end
def unknown_tag(tag, markup, tokens) def unknown_tag(tag, markup, tokens)