🤖 Pick PR #58786 (Fixed declaration emit crash relate...) into release-5.5 (#58853)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
TypeScript Bot
2024-06-14 18:21:52 -07:00
committed by GitHub
parent 39c9eebf17
commit 552b07e795
25 changed files with 663 additions and 2 deletions

View File

@@ -8840,8 +8840,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);
}