cache.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.clear = clear;
  6. exports.clearPath = clearPath;
  7. exports.clearScope = clearScope;
  8. exports.getCachedPaths = getCachedPaths;
  9. exports.getOrCreateCachedPaths = getOrCreateCachedPaths;
  10. exports.scope = exports.path = void 0;
  11. let pathsCache = new WeakMap();
  12. exports.path = pathsCache;
  13. let scope = new WeakMap();
  14. exports.scope = scope;
  15. function clear() {
  16. clearPath();
  17. clearScope();
  18. }
  19. function clearPath() {
  20. exports.path = pathsCache = new WeakMap();
  21. }
  22. function clearScope() {
  23. exports.scope = scope = new WeakMap();
  24. }
  25. const nullHub = Object.freeze({});
  26. function getCachedPaths(hub, parent) {
  27. var _pathsCache$get, _hub;
  28. {
  29. hub = null;
  30. }
  31. return (_pathsCache$get = pathsCache.get((_hub = hub) != null ? _hub : nullHub)) == null ? void 0 : _pathsCache$get.get(parent);
  32. }
  33. function getOrCreateCachedPaths(hub, parent) {
  34. var _hub2, _hub3;
  35. {
  36. hub = null;
  37. }
  38. let parents = pathsCache.get((_hub2 = hub) != null ? _hub2 : nullHub);
  39. if (!parents) pathsCache.set((_hub3 = hub) != null ? _hub3 : nullHub, parents = new WeakMap());
  40. let paths = parents.get(parent);
  41. if (!paths) parents.set(parent, paths = new Map());
  42. return paths;
  43. }
  44. //# sourceMappingURL=cache.js.map