-
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
#24210: Updated handling of undefined values in Enum types #39390
Conversation
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'm trying to clear out our PR backlog and finally reviewed this. Of course, I understand if you are not interested in finishing it.
@@ -34744,6 +34744,9 @@ namespace ts { | |||
Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value); | |||
} | |||
} | |||
else if (initializer.kind === SyntaxKind.Identifier && (initializer as Identifier).escapedText === "undefined") { | |||
return undefined; |
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.
Shouldn't there be an error here? I thought undefined
was supposed to be an error, but with an undefined-specific message.
} | ||
|
||
enum TeInf { | ||
"Infinity" = Infinity |
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.
Are Infinity and NaN supposed to be errors or not? Looking at the previous discussion, it seems only intended to be an error for const enum
.
})(TeNaN || (TeNaN = {})); | ||
var TeCornerValues; | ||
(function (TeCornerValues) { | ||
TeCornerValues[TeCornerValues["undefined"] = undefined] = "undefined"; |
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.
undefined/NaN/Infinity are still turned into quoted strings. That's not correct, is it?
To help with PR housekeeping, I'm going to close this PR since it's pretty old now. |
Fixes #24210
I've managed to identify two problems in #24210.
This is produced in the code below, along with the cryptic exception. However, I believe that this error should still be produced when user provided some wierd value like
"a" - "a"
.I've added additional clause to exclude the
undefined
from this logic. I've targeted the undefined keyword very specifically to avoid cases when something is evaluated toundefined
(limit regression).The substitution phase is trying to add Enum name prefix (as it is doing for combining multiple enum members). Effectively converting
Identifier
toPropertyAccessExpression
. In other words, convertingundefined
toEnumName.undefined
. While this make sense in some cases, I believe that undefined should have higher precedence here.I've added clause in
transformer.ts::trySubstituteNamespaceExportedName
to exclude theundefined
from this processing.