Use strict equality in generated JS #750
Merged
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.
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:
The one drawback to this change is that the following correct (read: same as Python) behavior will disappear:
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