You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
const enum should allow "Infinity" as a valid name #6153
This is intentional because Infinity is also a valid enum value; we disallow any name that might be a value because the lookup object only works if no names are values and no values are names.
Recommended fix is to just use Infinite instead of Infinity
The suggested implementation was to skip any leading -, then see if the next (or first) character is a digit. Only names matching this rule should be subject to restriction. This should allow Infinity and NaN but still disallow names like 5.
Activity
RyanCavanaugh commentedon Dec 18, 2015
This is intentional because
Infinityis also a valid enum value; we disallow any name that might be a value because the lookup object only works if no names are values and no values are names.Recommended fix is to just use
Infiniteinstead ofInfinitythe-reality-engineer commentedon Dec 18, 2015
What is the lookup object exactly? Using the name
Infinityas a property key is completely valid in javascript by the way.RyanCavanaugh commentedon Dec 18, 2015
I missed that this enum was
const. We don't need to enforce this rule for those.RyanCavanaugh commentedon Dec 18, 2015
(Lookup object, see http://stackoverflow.com/a/28818850/1704166)
[-]Enum should allow "Infinity" as a valid name[/-][+]const enum should allow "Infinity" as a valid name[/+]the-reality-engineer commentedon Dec 18, 2015
Not enforcing that rule for
const enumsounds great.RyanCavanaugh commentedon Jan 5, 2016
Approved even for non-
constenums.The suggested implementation was to skip any leading
-, then see if the next (or first) character is a digit. Only names matching this rule should be subject to restriction. This should allowInfinityandNaNbut still disallow names like5.DanielRosenwasser commentedon Jan 5, 2016
So what's the new rule now for numeric names? Same as before but make a special exception for "Infinity" and "NaN"?
Also Jordan Matthiesen (@jmatthiesen) asked about this a while back.
RyanCavanaugh commentedon Jan 5, 2016
Correct (as well as
-Infinity)YuichiNukiyama commentedon Mar 21, 2016
Ryan Cavanaugh (@RyanCavanaugh) A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($);. So, I think
-Infinityis invalid.RyanCavanaugh commentedon Mar 21, 2016
Enum members need not be identifiers - they can be quoted much like the property names in object literals
jbondc commentedon May 9, 2016
Reported here too #3572