Fix increment/decrement tags to use a separate counter namespace#91
Open
hugopl wants to merge 1 commit into
Open
Fix increment/decrement tags to use a separate counter namespace#91hugopl wants to merge 1 commit into
hugopl wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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
IncrementandDecrement, 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 on lines
+105
to
+107
| if @counters.has_key?(var) | ||
| return Any.new(@counters[var]) | ||
| end |
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 on lines
+95
to
+96
| def counter(name : String) : Int32 | ||
| @counters[name] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.