-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
esnext.reflect.get-metadata-keys.js
33 lines (29 loc) · 1.28 KB
/
esnext.reflect.get-metadata-keys.js
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
var $ = require('../internals/export');
// TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
var Set = require('../modules/es.set');
var ReflectMetadataModule = require('../internals/reflect-metadata');
var anObject = require('../internals/an-object');
var getPrototypeOf = require('../internals/object-get-prototype-of');
var iterate = require('../internals/iterate');
var ordinaryOwnMetadataKeys = ReflectMetadataModule.keys;
var toMetadataKey = ReflectMetadataModule.toKey;
var from = function (iter) {
var result = [];
iterate(iter, result.push, { that: result });
return result;
};
var ordinaryMetadataKeys = function (O, P) {
var oKeys = ordinaryOwnMetadataKeys(O, P);
var parent = getPrototypeOf(O);
if (parent === null) return oKeys;
var pKeys = ordinaryMetadataKeys(parent, P);
return pKeys.length ? oKeys.length ? from(new Set(oKeys.concat(pKeys))) : pKeys : oKeys;
};
// `Reflect.getMetadataKeys` method
// https://github.com/rbuckton/reflect-metadata
$({ target: 'Reflect', stat: true }, {
getMetadataKeys: function getMetadataKeys(target /* , targetKey */) {
var targetKey = arguments.length < 2 ? undefined : toMetadataKey(arguments[1]);
return ordinaryMetadataKeys(anObject(target), targetKey);
}
});