Skip to content

Fix increment/decrement tags to use a separate counter namespace#91

Open
hugopl wants to merge 1 commit into
amberframework:masterfrom
hugopl:increment-decrement
Open

Fix increment/decrement tags to use a separate counter namespace#91
hugopl wants to merge 1 commit into
amberframework:masterfrom
hugopl:increment-decrement

Conversation

@hugopl
Copy link
Copy Markdown
Collaborator

@hugopl hugopl commented May 8, 2026

increment/decrement now maintain their own counter namespace independent of assign variables, output the counter value to the template (increment post-increments, decrement pre-decrements), and fall back to the counter namespace when a variable is not found in the assign namespace.

increment/decrement now maintain their own counter namespace independent
of assign variables, output the counter value to the template (increment
post-increments, decrement pre-decrements), and fall back to the counter
namespace when a variable is not found in the assign namespace.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Liquid’s {% increment %} / {% decrement %} behavior to use a dedicated counter namespace (separate from assigned variables), emit the counter value into the output, and allow template variable lookups to fall back to counters when no assigned variable exists.

Changes:

  • Render {% increment %} / {% decrement %} by writing the counter value to the output and updating a dedicated counter store.
  • Add counter storage and APIs to Context, and extend variable lookup to fall back to counters when appropriate.
  • Add codegen support for Increment and Decrement, and unpend the corresponding golden integration tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/liquid/render_visitor.cr Switches increment/decrement rendering to use Context counters and output the counter value.
src/liquid/context.cr Introduces @counters plus increment/decrement helpers and adds counter fallback in get.
src/liquid/codegen_visitor.cr Adds code generation for increment/decrement blocks.
spec/integration/golden_liquid.pending Removes increment/decrement tests from the pending list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/liquid/context.cr
Comment on lines +105 to +107
if @counters.has_key?(var)
return Any.new(@counters[var])
end
Comment thread src/liquid/context.cr
Comment on lines 99 to +107
# Fetch a variable from context, add `UndefinedVariable` error if the variable isn't found and behave according the
# error mode.
def get(var : String) : Any
value = @data[var]?
return value if value

if @counters.has_key?(var)
return Any.new(@counters[var])
end
Comment thread src/liquid/context.cr
Comment on lines +95 to +96
def counter(name : String) : Int32
@counters[name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants