-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Disallow negative numbers in create numeric literal (take 2) #56570
Disallow negative numbers in create numeric literal (take 2) #56570
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
This looks good to me besides the test diff. IIRC our intention was to investigate actually adding an infinity/nan type, so we're leaving the status quo on |
I can confirm that's the intention here. Only negative finite numbers should be affected by this change, and it just forbids creating "wrong" AST nodes like that. |
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.
Actually, one suggestion to directly negate instead of using abs; this matches another change made in #56565 (which I am going to merge first, funnily your code would have caught this bug albeit without a test).
…bers-in-create-numeric-literal-2
Yeah, that PR reminded me that I was supposed to re-propose this change :)
done |
…ft#56570) Co-authored-by: Jake Bailey <[email protected]>
- append a `ValueMinus` string to numeric enum member names, if a name is not explicitly provided. - create negative numeric enum member values using `ts.factory.createPrefixUnaryExpression()` Previous behavior: When there is no name explicitly provided for them, numeric enum member names are constructed by prefixing the number with a `Value` string. The code did not take negative numbers into account, which resulted in enum members like: `_100 = -100`. Additionally, since Typescript 5.4 (see microsoft/TypeScript#56570), the `tsEnumMember` function failes on negative enum members.
- append a `ValueMinus` string to numeric enum member names, if a name is not explicitly provided. - create negative numeric enum member values using `ts.factory.createPrefixUnaryExpression()` Previous behavior: When there is no name explicitly provided for them, numeric enum member names are constructed by prefixing the number with a `Value` string. The code did not take negative numbers into account, which resulted in enum members like: `_100 = -100`. Additionally, since Typescript 5.4 (see microsoft/TypeScript#56570), the `tsEnumMember` function failes on negative enum members.
reverts #56422 which was a revert of #55268 but this version now focuses on negative numbers alone - without making any changes to
Infinity
(and that was the only reason why the original PR was reverted), cc @jakebaileythis would prevent issues like #56562 😉