mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Ensure const enum members with same value have same type identity
This commit is contained in:
@@ -3667,12 +3667,23 @@ namespace ts {
|
||||
return links.declaredType;
|
||||
}
|
||||
|
||||
function createEnumType(symbol: Symbol): Type {
|
||||
const type = createType(TypeFlags.Enum);
|
||||
type.symbol = symbol;
|
||||
return type;
|
||||
}
|
||||
|
||||
function getEnumMemberType(symbol: Symbol): Type {
|
||||
const links = getSymbolLinks(getParentOfSymbol(symbol));
|
||||
const map = links.enumMemberTypes || (links.enumMemberTypes = {});
|
||||
const value = "" + getEnumMemberValue(<EnumMember>symbol.valueDeclaration);
|
||||
return map[value] || (map[value] = createEnumType(symbol));
|
||||
}
|
||||
|
||||
function getDeclaredTypeOfEnum(symbol: Symbol): Type {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (!links.declaredType) {
|
||||
const type = createType(TypeFlags.Enum);
|
||||
type.symbol = symbol;
|
||||
links.declaredType = type;
|
||||
links.declaredType = symbol.flags & SymbolFlags.EnumMember ? getEnumMemberType(symbol) : createEnumType(symbol);
|
||||
}
|
||||
return links.declaredType;
|
||||
}
|
||||
|
||||
@@ -2136,6 +2136,7 @@ namespace ts {
|
||||
isDeclarationWithCollidingName?: boolean; // True if symbol is block scoped redeclaration
|
||||
bindingElement?: BindingElement; // Binding element associated with property symbol
|
||||
exportsSomeValue?: boolean; // True if module exports some value (not just types)
|
||||
enumMemberTypes?: Map<Type>; // Enum member types indexed by enum value
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
Reference in New Issue
Block a user