Fix compiler output equivalence and add comprehensive tests

- Fix forloop.first/last/size lookups to try hash key before method call
- Fix tablerow cols parameter to use attributes['cols'] not @cols
- Fix tablerow output format to match interpreter (newlines, row boundaries)
- Fix capture compiler to access @body directly instead of iterating nodelist
- Add CompiledTemplate class to encapsulate code and external_tags
- Add external filter support via filter_handler
- Add debug mode warnings for external tag/filter calls
- Add Ruby 3.3 compatibility shim for peek_byte/scan_byte
- Add comprehensive unit tests for output equivalence
- Add benchmark comparing compiled vs interpreted rendering

All 30 test templates now produce identical output between compiled
Ruby and interpreted Liquid. Pre-compiled Ruby is 1.68x faster.
This commit is contained in:
Claude
2025-12-31 14:58:06 +00:00
parent e0f856fd11
commit 7be2922f91
13 changed files with 715 additions and 180 deletions
+26
View File
@@ -0,0 +1,26 @@
# frozen_string_literal: true
# Compatibility shim for Ruby 3.3
# The Liquid library uses peek_byte and scan_byte which are only available in Ruby 3.4+
require 'strscan'
unless StringScanner.method_defined?(:peek_byte)
class StringScanner
def peek_byte
return nil if eos?
string.getbyte(pos)
end
end
end
unless StringScanner.method_defined?(:scan_byte)
class StringScanner
def scan_byte
return nil if eos?
byte = string.getbyte(pos)
self.pos += 1
byte
end
end
end