Skip to content

Improve unary with sign expression handling#2224

Open
xenova wants to merge 1 commit into
mainfrom
fix-unary-with-in
Open

Improve unary with sign expression handling#2224
xenova wants to merge 1 commit into
mainfrom
fix-unary-with-in

Conversation

@xenova

@xenova xenova commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

fixes {{ 0 in axes or -4 in axes }}


Note

Medium Risk
Changes expression parsing precedence and unary evaluation across lexer/parser/runtime; behavior shifts for any template using +/- before identifiers or in, though tests lock expected outcomes.

Overview
Fixes templates like {% if 0 in axes or -4 in axes %} by treating leading +/- as unary sign on the following value, not as binary subtraction glued to in.

The parser adds parseUnarySignExpression (used before filters) so expressions such as -4 in axes, -apple | abs, and -(apple + 1) in arr build UnaryExpression nodes. The lexer now folds fractional digits after a unary sign into one numeric token (e.g. -1.5). The runtime evaluates unary +/- on numbers and booleans; float formatting and FloatValue.toString() handle -0.0 and whole-number floats consistently. Coverage is extended via UNARY_SIGN_EXPRESSIONS in templates.test.js.

Reviewed by Cursor Bugbot for commit 48987c9. Bugbot is set up for automated code reviews on this repo. Configure here.

@xenova xenova requested a review from nico-martin June 10, 2026 04:02
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.

3 participants