Address comments

This commit is contained in:
Peter Zhu
2020-10-26 15:11:00 -04:00
parent fe66edb825
commit 0bedc71854
7 changed files with 23 additions and 30 deletions

View File

@@ -22,6 +22,6 @@ group :test do
gem 'rubocop-performance', require: false
platform :mri, :truffleruby do
gem 'liquid-c', github: 'Shopify/liquid-c', ref: 'pz-block-body-buffer'
gem 'liquid-c', github: 'Shopify/liquid-c', ref: 'master'
end
end

View File

@@ -11,9 +11,9 @@ module Liquid
def parse(tokens)
@body = new_body
while parse_body(@body, tokens)
while parse_body(@body, tokens, partial: true)
end
@body.freeze(parse_context)
@body.freeze
end
# For backwards compatibility
@@ -68,7 +68,9 @@ module Liquid
end
# @api public
def parse_body(body, tokens)
def parse_body(body, tokens, partial: false)
block_terminated = true
if parse_context.depth >= MAX_DEPTH
raise StackLevelError, "Nesting too deep"
end
@@ -77,7 +79,10 @@ module Liquid
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
@blank &&= body.blank?
return false if end_tag_name == block_delimiter
if end_tag_name == block_delimiter
block_terminated = false
next
end
raise_tag_never_closed(block_name) unless end_tag_name
# this tag is not registered with the system
@@ -88,7 +93,12 @@ module Liquid
parse_context.depth -= 1
end
true
unless partial
body.remove_blank_strings if body.blank?
body.freeze
end
block_terminated
end
end
end

View File

@@ -16,11 +16,10 @@ module Liquid
def initialize
@nodelist = []
@blank = true
@frozen = false
end
def parse(tokenizer, parse_context, &block)
raise FrozenError, "can't modify frozen Liquid::BlockBody" if @frozen
raise FrozenError, "can't modify frozen Liquid::BlockBody" if frozen?
parse_context.line_number = tokenizer.line_number
@@ -31,8 +30,9 @@ module Liquid
end
end
def freeze(_context)
@frozen = true
def freeze
@nodelist.freeze
super
end
private def parse_for_liquid_tag(tokenizer, parse_context)
@@ -199,7 +199,7 @@ module Liquid
end
def render_to_output_buffer(context, output)
raise "Can only render when frozen" unless @frozen
raise "Can only render when frozen" unless frozen?
context.resource_limits.increment_render_score(@nodelist.length)

View File

@@ -22,7 +22,7 @@ module Liquid
def parse(tokenizer, parse_context)
while parse_body(tokenizer)
end
@body.freeze(parse_context)
@body.freeze
rescue SyntaxError => e
e.line_number ||= parse_context.line_number
raise

View File

@@ -20,14 +20,7 @@ module Liquid
def parse(tokens)
body = new_body
while parse_body(body, tokens)
body.freeze(parse_context)
body = @blocks.last.attachment
end
body.freeze(parse_context)
if blank?
@blocks.each { |condition| condition.attachment.remove_blank_strings }
end
body = @blocks.last.attachment while parse_body(body, tokens)
end
def nodelist

View File

@@ -61,12 +61,6 @@ module Liquid
def parse(tokens)
if parse_body(@for_block, tokens)
parse_body(@else_block, tokens)
@else_block.freeze(parse_context)
end
@for_block.freeze(parse_context)
if blank?
@for_block.remove_blank_strings
@else_block&.remove_blank_strings
end
end

View File

@@ -31,10 +31,6 @@ module Liquid
def parse(tokens)
while parse_body(@blocks.last.attachment, tokens)
end
@blocks.each { |block| block.attachment.freeze(parse_context) }
if blank?
@blocks.each { |condition| condition.attachment.remove_blank_strings }
end
end
def unknown_tag(tag, markup, tokens)