esnext.reflect.get-metadata-keys.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. // TODO: Remove from `core-js@4`
  2. var $ = require('../internals/export');
  3. var uncurryThis = require('../internals/function-uncurry-this');
  4. var ReflectMetadataModule = require('../internals/reflect-metadata');
  5. var anObject = require('../internals/an-object');
  6. var getPrototypeOf = require('../internals/object-get-prototype-of');
  7. var $arrayUniqueBy = require('../internals/array-unique-by');
  8. var arrayUniqueBy = uncurryThis($arrayUniqueBy);
  9. var concat = uncurryThis([].concat);
  10. var ordinaryOwnMetadataKeys = ReflectMetadataModule.keys;
  11. var toMetadataKey = ReflectMetadataModule.toKey;
  12. var ordinaryMetadataKeys = function (O, P) {
  13. var oKeys = ordinaryOwnMetadataKeys(O, P);
  14. var parent = getPrototypeOf(O);
  15. if (parent === null) return oKeys;
  16. var pKeys = ordinaryMetadataKeys(parent, P);
  17. return pKeys.length ? oKeys.length ? arrayUniqueBy(concat(oKeys, pKeys)) : pKeys : oKeys;
  18. };
  19. // `Reflect.getMetadataKeys` method
  20. // https://github.com/rbuckton/reflect-metadata
  21. $({ target: 'Reflect', stat: true }, {
  22. getMetadataKeys: function getMetadataKeys(target /* , targetKey */) {
  23. var targetKey = arguments.length < 2 ? undefined : toMetadataKey(arguments[1]);
  24. return ordinaryMetadataKeys(anObject(target), targetKey);
  25. }
  26. });