All files / common/src/annotation/target annotation-target.utils.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33            10x       1495x 419x   1076x 1076x 28x     1048x     10x       5x 5x 5x   5x      
import { ConstructorType, Prototype } from '@aspectjs/common/utils';
import { AnnotationTarget } from './annotation-target';
 
/**
 * @internal
 */
export function _findPropertyDescriptor(
  obj: Prototype | ConstructorType,
  propertyKey: string | symbol,
): PropertyDescriptor | undefined {
  if (!obj) {
    return;
  }
  const descriptor = Object.getOwnPropertyDescriptor(obj, propertyKey);
  if (descriptor) {
    return descriptor;
  }
 
  return _findPropertyDescriptor(Object.getPrototypeOf(obj), propertyKey);
}
 
export function defuseAdvices<R = unknown>(
  target: AnnotationTarget,
  fn: () => R,
) {
  try {
    target.defineMetadata('@ajs:defuseAdvices', true);
    return fn();
  } finally {
    target.defineMetadata('@ajs:defuseAdvices', false);
  }
}