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. |
jakebailey
left a comment
There was a problem hiding this comment.
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 <5341706+jakebailey@users.noreply.github.com>
- 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.
- 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 😉