1 | // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
|
---|
2 | var Map = require('../modules/es.map');
|
---|
3 | var WeakMap = require('../modules/es.weak-map');
|
---|
4 | var create = require('../internals/object-create');
|
---|
5 | var isObject = require('../internals/is-object');
|
---|
6 |
|
---|
7 | var Node = function () {
|
---|
8 | // keys
|
---|
9 | this.object = null;
|
---|
10 | this.symbol = null;
|
---|
11 | // child nodes
|
---|
12 | this.primitives = null;
|
---|
13 | this.objectsByIndex = create(null);
|
---|
14 | };
|
---|
15 |
|
---|
16 | Node.prototype.get = function (key, initializer) {
|
---|
17 | return this[key] || (this[key] = initializer());
|
---|
18 | };
|
---|
19 |
|
---|
20 | Node.prototype.next = function (i, it, IS_OBJECT) {
|
---|
21 | var store = IS_OBJECT
|
---|
22 | ? this.objectsByIndex[i] || (this.objectsByIndex[i] = new WeakMap())
|
---|
23 | : this.primitives || (this.primitives = new Map());
|
---|
24 | var entry = store.get(it);
|
---|
25 | if (!entry) store.set(it, entry = new Node());
|
---|
26 | return entry;
|
---|
27 | };
|
---|
28 |
|
---|
29 | var root = new Node();
|
---|
30 |
|
---|
31 | module.exports = function () {
|
---|
32 | var active = root;
|
---|
33 | var length = arguments.length;
|
---|
34 | var i, it;
|
---|
35 | // for prevent leaking, start from objects
|
---|
36 | for (i = 0; i < length; i++) {
|
---|
37 | if (isObject(it = arguments[i])) active = active.next(i, it, true);
|
---|
38 | }
|
---|
39 | if (this === Object && active === root) throw TypeError('Composite keys must contain a non-primitive component');
|
---|
40 | for (i = 0; i < length; i++) {
|
---|
41 | if (!isObject(it = arguments[i])) active = active.next(i, it, false);
|
---|
42 | } return active;
|
---|
43 | };
|
---|