Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// we are promised there are no conflicts
const kwargs = deserializeValue(stack, p.type, p.optional, p.name, parameters);
args.push(kwargs);
} else {
const val = parameters[p.name];
if (val === undefined && !p.optional) {
throw new Error(`Missing required parameter '${p.name}' for ${method.parentType.fqn}.${method.name}`);
}
if (val !== undefined) {
args.push(deserializeValue(stack, p.type, p.optional, p.name, val));
}
}
}
if (reflect.Initializer.isInitializer(method)) {
return new typeClass(...args);
}
const methodFn: (...args: any[]) => any = typeClass[method.name];
if (!methodFn) {
throw new Error(`Cannot find method named ${method.name} in ${typeClass.fqn}`);
}
return methodFn.apply(typeClass, args);
}
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}`);
}