mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 12:19:32 -05:00
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user