-
Notifications
You must be signed in to change notification settings - Fork 103
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
feat(): fix unary, math, and conditional operatiors + test updates #277
Conversation
TroyAlford
commented
Oct 5, 2024
- fully working evaluation of unary/binary/math operators
- clean up a bunch of tests
} | ||
return undefined | ||
return handleNaN(binaryResult) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this helper ensures that we actually treat NaN
as a real value and output its string version when appropriate.
if (expression.name === 'Infinity') return Infinity | ||
if (expression.name === '-Infinity') return -Infinity | ||
if (expression.name === 'NaN') return NaN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infinity
, -Infinity
, and NaN
are valid JS values — but we were throwing them away and incorrectly using them prior.
const unaryValue = this.#parseExpression( | ||
expression.argument as AcornJSX.Expression, | ||
scope, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is needed in order to handle -Infinity
correctly. This value actually comes through as a unary operator -
along with the Literal Infinity
— but by parsing it, we can get it back as -Infinity
correctly.