mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 12:19:32 -05:00
Fixed declaration emit crash related to enum entity name expressions (#58786)
This commit is contained in:
committed by
GitHub
parent
6f06eb1b27
commit
e370c867c0
@@ -8882,8 +8882,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
else {
|
||||
const type = getWidenedType(getRegularTypeOfExpression(node.expression));
|
||||
const computedPropertyNameType = typeToTypeNodeHelper(type, context);
|
||||
Debug.assertNode(computedPropertyNameType, isLiteralTypeNode);
|
||||
const literal = computedPropertyNameType.literal;
|
||||
let literal;
|
||||
if (isLiteralTypeNode(computedPropertyNameType)) {
|
||||
literal = computedPropertyNameType.literal;
|
||||
}
|
||||
else {
|
||||
const evaluated = evaluateEntityNameExpression(node.expression);
|
||||
const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral(evaluated.value, /*isSingleQuote*/ undefined) :
|
||||
typeof evaluated.value === "number" ? factory.createNumericLiteral(evaluated.value, /*numericLiteralFlags*/ 0) :
|
||||
undefined;
|
||||
if (!literalNode) {
|
||||
if (isImportTypeNode(computedPropertyNameType)) {
|
||||
trackComputedName(node.expression, context.enclosingDeclaration, context);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
literal = literalNode;
|
||||
}
|
||||
if (literal.kind === SyntaxKind.StringLiteral && isIdentifierText(literal.text, getEmitScriptTarget(compilerOptions))) {
|
||||
return factory.createIdentifier(literal.text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user