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.
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 numeric literals with negative numbers #55268
Disallow numeric literals with negative numbers #55268
Changes from 1 commit
167a0ee
7fc1803
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 shows how
createNumericLiteral
is still a somewhat weird thing.Infinity
is allowed because parsed numbers are "normalized" to text here:TypeScript/src/compiler/scanner.ts
Lines 1765 to 1773 in 83f3abd
So a sufficiently long number in the input can be stringified to
Infinity
🤷♂️ I find it weird an there is an issue about it that is labeled as a bug. While it doesn't mentionInfinity
case the issue there is basically related to the same "normalization".This issue is certainly fixable but I'm not 100% sure if you'd really want to fix it.
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.
Don't change this to
Infinity
since we really should consider that invalid as well. I'd just use a large value that we're unlikely to actually hit in a generator, something like2 ** 32 - 1
(max uint32). The only reason it's set to-1
is to make it obvious something went wrong in tests.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.
Ye, I committed it this way specifically to add this PR comment 😅
Strong agree, I had versions of this work that forbid this as well but decided to roll them back and only start the conversation about this for now. I'm open to following up with further changes but it seems that the mentioned "normalization" of parsed numeric literals is relied upon in a couple of places. They can be adjusted but I'm not sure if this is something you'd like to do. In a way, it would be easiest to just drop this whole normalization altogether and just cast parsed text to string in those other places (to produce correct resolved property names etc).
pushed out a change with
Number.MAX_SAFE_INTEGER
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.
I really hope no one is relying on this.