Uh oh!
There was an error while loading. Please reload this page.
Don't emit enum members as evaluated Infinity/NaN when their symbols are shadowed - #55107
Conversation
| if (typeof value === "string") { | ||
| return factory.createStringLiteral(value); | ||
| } | ||
| if (Number.isNaN(value)) { |
There was a problem hiding this comment.
alternatively, I could just not use the constant value in those cases and fallback to the other branch - that would likely work. But I feel that NaN and Infinity should not be passed to factory.createNumericLiteral so some changes to this branch of code here would have to be done anyway. I also like that those evaluated, yet shadowed, Infinity and NaN are normalized~ by the proposed changes.
Infinity/NaN when their values are shadowedInfinity/NaN when their symbols are shadowed31c3e64 to
24cd553CompareBruce Pascoe (fatcerberus)
commented
Jul 22, 2023
Just for completeness’ sake, how does this interact with |
Mateusz Burzyński (Andarist)
commented
Jul 22, 2023
|
| ? factory.createIdentifier("NaN") | ||
| : factory.createBinaryExpression(factory.createNumericLiteral(0), SyntaxKind.SlashToken, factory.createNumericLiteral(0)); | ||
| } | ||
| if (!isFinite(value)) { |
There was a problem hiding this comment.
What do you think of this alternative way to write it?
if(!isFinite(value){letresult: Node=resolver.isNameReferencingGlobalValueAtLocation("Infinity",member) ?
factory.createIdentifier("Infinity") :
factory.createBinaryExpression(factory.createNumericLiteral(0),SyntaxKind.SlashToken,factory.createNumericLiteral(0));if(value<0){result=factory.createPrefixUnaryExpression(SyntaxKind.MinusToken,result);}returnresult;}There was a problem hiding this comment.
I guess that would emit as -(1/0)?
There was a problem hiding this comment.
What do you think of this alternative way to write it?
That's what I started with :p
ed2cc57
I guess that would emit as -(1/0)?
and why I changed it to the current version 😉
| //// [enumShadowedInfinityNaN2.ts] | ||
| // repro https://github.com/microsoft/TypeScript/issues/55091 | ||
| let Infinity = 3; |
There was a problem hiding this comment.
Are there any more convincing global names that could get shadowed than Infinity and NaN? It's a stretch for people to create local names Infinity or NaN.
There was a problem hiding this comment.
I think those are the only 2 that can be produced by the „constant evaluation”
It's a stretch for people to create local names Infinity or NaN.
cant disagree :p the issue was labeled as a bug and not a wontfix, it’s similar to the merged: #55018
c8001bd to
dc59819Comparedc59819 to
0bcbc62CompareTypeScript Bot (typescript-bot)
commented
Mar 24, 2026
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
fixes#55091