Handle merged enums

This commit is contained in:
Nathan Shively-Sanders 2015-12-10 14:28:29 -08:00
parent ff0138878d
commit a995b23e4a
2 changed files with 33 additions and 5 deletions

View file

@ -5762,12 +5762,11 @@ namespace ts {
target.symbol.flags & SymbolFlags.ConstEnum) {
return Ternary.False;
}
const sourceDecl = <EnumDeclaration>getDeclarationOfKind(source.symbol, SyntaxKind.EnumDeclaration);
const targetDecl = <EnumDeclaration>getDeclarationOfKind(target.symbol, SyntaxKind.EnumDeclaration);
const targetMembers = arrayToMap(targetDecl.members, member => getTextOfPropertyName(<PropertyName>member.name));
for (const member of sourceDecl.members) {
const targetMembers = getEnumMembers(target.symbol);
const targetNames = arrayToMap(targetMembers, member => getTextOfPropertyName(<PropertyName>member.name));
for (const member of getEnumMembers(source.symbol)) {
const name = getTextOfPropertyName(<PropertyName>member.name);
if (!hasProperty(targetMembers, name)) {
if (!hasProperty(targetNames, name)) {
reportError(Diagnostics.Property_0_is_missing_in_type_1,
name,
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
@ -5778,6 +5777,20 @@ namespace ts {
}
}
function getEnumMembers(symbol: Symbol): EnumMember[] {
const declarations = getDeclarationsOfKind(symbol, SyntaxKind.EnumDeclaration);
if (!declarations) {
return emptyArray;
}
const members: EnumMember[] = [];
for (const declaration of declarations) {
for (const member of (<EnumDeclaration>declaration).members) {
members.push(member);
}
}
return members;
}
// Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case
// when structural type comparisons have been started for 10 or more instantiations of the same generic type. It is possible,
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely expanding.

View file

@ -27,6 +27,21 @@ namespace ts {
return undefined;
}
export function getDeclarationsOfKind(symbol: Symbol, kind: SyntaxKind): Declaration[] {
const declarations = symbol.declarations;
if (declarations) {
const declarationsOfKind: Declaration[] = [];
for (const declaration of declarations) {
if (declaration.kind === kind) {
declarationsOfKind.push(declaration);
}
}
return declarationsOfKind;
}
return undefined;
}
export interface StringSymbolWriter extends SymbolWriter {
string(): string;
}