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

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