Skip to content

Commit

Permalink
Change the memberTypes of an EnumType to a (possibly sparse, but prob…
Browse files Browse the repository at this point in the history
…ably not ) array.
  • Loading branch information
Andy Hanson committed Oct 6, 2016
1 parent 4ca311a commit d566eb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3868,15 +3868,15 @@ namespace ts {
enumType.symbol = symbol;
if (enumHasLiteralMembers(symbol)) {
const memberTypeList: Type[] = [];
const memberTypes = new NumberMap<number, EnumLiteralType>();
const memberTypes: { [enumMemberValue: number]: EnumLiteralType } = [];
for (const declaration of enumType.symbol.declarations) {
if (declaration.kind === SyntaxKind.EnumDeclaration) {
computeEnumMemberValues(<EnumDeclaration>declaration);
for (const member of (<EnumDeclaration>declaration).members) {
const memberSymbol = getSymbolOfNode(member);
const value = getEnumMemberValue(member);
if (!memberTypes.get(value)) {
memberTypeList.push(setAndReturn(memberTypes, value, createEnumLiteralType(memberSymbol, enumType, "" + value)));
if (!memberTypes[value]) {
memberTypeList.push(memberTypes[value] = createEnumLiteralType(memberSymbol, enumType, "" + value));
}
}
}
Expand All @@ -3897,7 +3897,7 @@ namespace ts {
if (!links.declaredType) {
const enumType = <EnumType>getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
links.declaredType = enumType.flags & TypeFlags.Union ?
enumType.memberTypes.get(getEnumMemberValue(<EnumDeclaration>symbol.valueDeclaration)) :
enumType.memberTypes[getEnumMemberValue(<EnumDeclaration>symbol.valueDeclaration)] :
enumType;
}
return links.declaredType;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ namespace ts {

// Enum types (TypeFlags.Enum)
export interface EnumType extends Type {
memberTypes: Map<number, EnumLiteralType>;
memberTypes: { [enumMemberValue: number]: EnumLiteralType };
}

// Enum types (TypeFlags.EnumLiteral)
Expand Down

0 comments on commit d566eb5

Please sign in to comment.