Repository navigation
fix: parenthesize a unary base in the compiled ** expression - #7565
Conversation
[Medium impact] The PR appears safe to merge; no new blocking issues were found. SummaryFixes JavaScript build errors when a negative number or negated variable is raised to a power.
Reviews (6) · Last reviewed commit: "Merge branch 'main' into fix-negative-ex..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
masenf
left a comment
There was a problem hiding this comment.
thanks, appreciate the fix
All Submissions:
Type of change
Changes To Core Features:
Description
number_exponent_operationrenders({lhs} ** {rhs})as is. JavaScript doesn't allow a unary expression as the base of**(-2 ** 2is a SyntaxError, unlike Python where it means-(2 ** 2)), so when the base is a negative literal or a negated var the compiled page doesn't build. For example(-State.velocity) ** 2renders as(-(…velocity…) ** 2)andrx.Var.create(-2) ** State.nas(-2 ** …n…).The base is now parenthesized when it starts with a unary operator, so those become
((-(…velocity…)) ** 2)and((-2) ** …n…). Everything else renders exactly as before ((1 ** 2),(x ** -1), and-(x ** 2)from-x ** 2), so no existing snapshot changes.Before / After with a one-page app,
rx.text("squared: ", (-State.velocity) ** 2), runningreflex export --frontend-only:I also ran the rendered expressions through Node and they match Python:
((-(x)) ** 2)is 9,((-2) ** x)is -8,((-2.5) ** 2)is 6.25 forx = 3.test_exponent_parenthesizes_a_unary_basecovers the negative-literal and negated-var bases and the cases that must stay unwrapped, and fails on main with'(-2 ** 3)' == '((-2) ** 3)'.tests/unitspasses (11965 passed), along with ruff and pyright on the changed files.