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

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