@@ -37302,7 +37302,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37302
37302
texts.push(span.literal.text);
37303
37303
types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType);
37304
37304
}
37305
- return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node, /*contextFlags*/ undefined) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
37305
+ if (isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node, /*contextFlags*/ undefined) || unknownType, isTemplateLiteralContextualType)) {
37306
+ return getTemplateLiteralType(texts, types);
37307
+ }
37308
+ const evaluated = node.parent.kind !== SyntaxKind.TaggedTemplateExpression && evaluateTemplateExpression(node);
37309
+ return evaluated ? getFreshTypeOfLiteralType(getStringLiteralType(evaluated)) : stringType;
37306
37310
}
37307
37311
37308
37312
function isTemplateLiteralContextualType(type: Type): boolean {
@@ -43579,7 +43583,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
43579
43583
return value;
43580
43584
}
43581
43585
43582
- function evaluate(expr: Expression, location: Declaration): string | number | undefined {
43586
+ function evaluate(expr: Expression, location? : Declaration): string | number | undefined {
43583
43587
switch (expr.kind) {
43584
43588
case SyntaxKind.PrefixUnaryExpression:
43585
43589
const value = evaluate((expr as PrefixUnaryExpression).operand, location);
@@ -43636,11 +43640,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
43636
43640
const symbol = resolveEntityName(expr, SymbolFlags.Value, /*ignoreErrors*/ true);
43637
43641
if (symbol) {
43638
43642
if (symbol.flags & SymbolFlags.EnumMember) {
43639
- return evaluateEnumMember(expr, symbol, location);
43643
+ return location ? evaluateEnumMember(expr, symbol, location) : getEnumMemberValue(symbol.valueDeclaration as EnumMember );
43640
43644
}
43641
43645
if (isConstVariable(symbol)) {
43642
43646
const declaration = symbol.valueDeclaration as VariableDeclaration | undefined;
43643
- if (declaration && !declaration.type && declaration.initializer && declaration !== location && isBlockScopedNameDeclaredBeforeUse(declaration, location)) {
43647
+ if (declaration && !declaration.type && declaration.initializer && (!location || declaration !== location && isBlockScopedNameDeclaredBeforeUse(declaration, location) )) {
43644
43648
return evaluate(declaration.initializer, declaration);
43645
43649
}
43646
43650
}
@@ -43655,7 +43659,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
43655
43659
const name = escapeLeadingUnderscores(((expr as ElementAccessExpression).argumentExpression as StringLiteralLike).text);
43656
43660
const member = rootSymbol.exports!.get(name);
43657
43661
if (member) {
43658
- return evaluateEnumMember(expr, member, location);
43662
+ return location ? evaluateEnumMember(expr, member, location) : getEnumMemberValue(member.valueDeclaration as EnumMember );
43659
43663
}
43660
43664
}
43661
43665
}
@@ -43677,7 +43681,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
43677
43681
return getEnumMemberValue(declaration as EnumMember);
43678
43682
}
43679
43683
43680
- function evaluateTemplateExpression(expr: TemplateExpression, location: Declaration) {
43684
+ function evaluateTemplateExpression(expr: TemplateExpression, location? : Declaration) {
43681
43685
let result = expr.head.text;
43682
43686
for (const span of expr.templateSpans) {
43683
43687
const value = evaluate(span.expression, location);
0 commit comments