Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strict equality in generated JS #750

Merged
merged 1 commit into from Apr 2, 2023

Conversation

jonaengs
Copy link
Contributor

@jonaengs jonaengs commented Mar 30, 2023

Apologies for the duplicate PR (original is #743). I screwed up some stuff when trying to rename the branch the original PR was based on.

Use strict equality and inequality in generated javascript equality checks.

Reason: Javascript's strict equality semantically more similar to Python's notion of equality than the previously used equality. This difference mainly stems from Javascript's heavy reliance on type coercion when evaluating the equality operator. The strict equality operator avoids this type coercion.

Some examples showing why this is a good change:

// Javascript equality:
2 == "2"; // true
"1,2" == [1, 2]; // true
# Python equality:
2 == "2" # False
"1,2" == [1, 2]  # False
// Javascript strict equality:
2 === "2"; // false
"1,2" === [1, 2]; // false

The one drawback to this change is that the following correct (read: same as Python) behavior will disappear:

1 == true; // true
0 == false // true

But I believe that this is a rather uncommon expression. This change will not affect the behavior of pc.cond(State.some_integer, ...). The change only affects this exact equality operation, with these exact operands.

Sources:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_inequality https://tc39.es/ecma262/#sec-isstrictlyequal
https://docs.python.org/3/reference/expressions.html

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

Nice, thanks for updating the tests!

@picklelo picklelo merged commit e811a84 into reflex-dev:main Apr 2, 2023
11 checks passed
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.

None yet

2 participants