source: trip-planner-front/node_modules/core-js/internals/composite-key.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1// TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
2var Map = require('../modules/es.map');
3var WeakMap = require('../modules/es.weak-map');
4var create = require('../internals/object-create');
5var isObject = require('../internals/is-object');
6
7var 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
16Node.prototype.get = function (key, initializer) {
17 return this[key] || (this[key] = initializer());
18};
19
20Node.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
29var root = new Node();
30
31module.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};
Note: See TracBrowser for help on using the repository browser.