Allow references to const variables with literal types in constant expressions
This commit is contained in:
Родитель
e0036e65e8
Коммит
2e0d0fcb6c
|
@ -46726,17 +46726,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
}
|
||||
if (isConstantVariable(symbol)) {
|
||||
const declaration = symbol.valueDeclaration;
|
||||
if (declaration && isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && (!location || declaration !== location && isBlockScopedNameDeclaredBeforeUse(declaration, location))) {
|
||||
const result = evaluate(declaration.initializer, declaration);
|
||||
if (location && getSourceFileOfNode(location) !== getSourceFileOfNode(declaration)) {
|
||||
return evaluatorResult(
|
||||
result.value,
|
||||
/*isSyntacticallyString*/ false,
|
||||
/*resolvedOtherFiles*/ true,
|
||||
/*hasExternalReferences*/ true,
|
||||
);
|
||||
if (declaration && isVariableDeclaration(declaration)) {
|
||||
if (!declaration.type && declaration.initializer && (!location || declaration !== location && isBlockScopedNameDeclaredBeforeUse(declaration, location))) {
|
||||
const result = evaluate(declaration.initializer, declaration);
|
||||
return location && getSourceFileOfNode(location) !== getSourceFileOfNode(declaration) ?
|
||||
evaluatorResult(result.value, /*isSyntacticallyString*/ false, /*resolvedOtherFiles*/ true, /*hasExternalReferences*/ true) :
|
||||
evaluatorResult(result.value, result.isSyntacticallyString, result.resolvedOtherFiles, /*hasExternalReferences*/ true);
|
||||
}
|
||||
if (declaration.type && declaration.type.kind === SyntaxKind.LiteralType) {
|
||||
const type = getTypeOfSymbol(symbol);
|
||||
if (type.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
|
||||
return evaluatorResult((type as LiteralType).value as string | number);
|
||||
}
|
||||
}
|
||||
return evaluatorResult(result.value, result.isSyntacticallyString, result.resolvedOtherFiles, /*hasExternalReferences*/ true);
|
||||
}
|
||||
}
|
||||
return evaluatorResult(/*value*/ undefined);
|
||||
|
|
Загрузка…
Ссылка в новой задаче