Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function dispatch(apiElement: ApiElement, fns: {
method(m: reflect.Method): T;
init(m: reflect.Initializer): T;
property(m: reflect.Property): T;
enumMember(m: reflect.EnumMember): T;
enumType(m: reflect.EnumType): T;
klass(m: reflect.ClassType): T;
iface(m: reflect.InterfaceType): T;
}) {
if (apiElement instanceof reflect.Method) { return fns.method(apiElement); }
if (apiElement instanceof reflect.Property) { return fns.property(apiElement); }
if (apiElement instanceof reflect.EnumMember) { return fns.enumMember(apiElement); }
if (apiElement instanceof reflect.ClassType) { return fns.klass(apiElement); }
if (apiElement instanceof reflect.InterfaceType) { return fns.iface(apiElement); }
if (apiElement instanceof reflect.Initializer) { return fns.init(apiElement); }
if (apiElement instanceof reflect.EnumType) { return fns.enumType(apiElement); }
throw new Error(`Unrecognized violator: ${apiElement}`);
}
export function getDocTag(documentable: reflect.Documentable, tag: string): string | undefined {
const t = documentable.docs.customTag(tag);
if (t) { return t; }
if ((documentable instanceof reflect.Property || documentable instanceof reflect.Method) && documentable.overrides) {
if (documentable.overrides.isClassType() || documentable.overrides.isInterfaceType()) {
const baseMembers = documentable.overrides.allMembers.filter(m => m.name === documentable.name);
for (const base of baseMembers) {
const baseTag = getDocTag(base, tag);
if (baseTag) {
return baseTag;
}
}
}
}
if (documentable instanceof reflect.ClassType || documentable instanceof reflect.InterfaceType) {
for (const base of documentable.interfaces) {
const baseTag = getDocTag(base, tag);
if (baseTag) {
return baseTag;