Repository navigation
fix: parenthesize a unary base in the compiled ** expression - #7565
darshjoshi wants to merge 4 commits into
Conversation
[Medium impact] The PR appears safe to merge; no outstanding findings remain. SummaryFixes JavaScript builds for powers with negative or negated bases.
Reviews (4) · Last reviewed commit: "Keep test_var.py as it is on the base br..." · Reviewed by Greptile |
Merging this PR will not alter performance
|
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/units/test_var.py">
<violation number="1" location="tests/units/test_var.py:1593">
P2: This test expects `code_uses_state_contexts` to recognize `useStateContext`, but the helper only recognizes `useContext(StateContexts...)`; the unit suite will fail. Use a representative `useContext(StateContexts.state)` snippet instead.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
| @pytest.mark.parametrize( | ||
| ("javascript_code", "expected"), | ||
| [ | ||
| ("const state = useStateContext('state')", True), |
There was a problem hiding this comment.
P2: This test expects code_uses_state_contexts to recognize useStateContext, but the helper only recognizes useContext(StateContexts...); the unit suite will fail. Use a representative useContext(StateContexts.state) snippet instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/units/test_var.py, line 1593:
<comment>This test expects `code_uses_state_contexts` to recognize `useStateContext`, but the helper only recognizes `useContext(StateContexts...)`; the unit suite will fail. Use a representative `useContext(StateContexts.state)` snippet instead.</comment>
<file context>
@@ -1598,6 +1587,17 @@ def test_retrieval():
+@pytest.mark.parametrize(
+ ("javascript_code", "expected"),
+ [
+ ("const state = useStateContext('state')", True),
+ ("const state = useContext(ThemeContext)", False),
+ ],
</file context>
| ("const state = useStateContext('state')", True), | |
| ("const state = useContext(StateContexts.state)", True), |
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.