Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _path = require("./path");
  7. var t = require("@babel/types");
  8. class TraversalContext {
  9. constructor(scope, opts, state, parentPath) {
  10. this.queue = null;
  11. this.priorityQueue = null;
  12. this.parentPath = parentPath;
  13. this.scope = scope;
  14. this.state = state;
  15. this.opts = opts;
  16. }
  17. shouldVisit(node) {
  18. const opts = this.opts;
  19. if (opts.enter || opts.exit) return true;
  20. if (opts[node.type]) return true;
  21. const keys = t.VISITOR_KEYS[node.type];
  22. if (!(keys != null && keys.length)) return false;
  23. for (const key of keys) {
  24. if (node[key]) return true;
  25. }
  26. return false;
  27. }
  28. create(node, obj, key, listKey) {
  29. return _path.default.get({
  30. parentPath: this.parentPath,
  31. parent: node,
  32. container: obj,
  33. key: key,
  34. listKey
  35. });
  36. }
  37. maybeQueue(path, notPriority) {
  38. if (this.queue) {
  39. if (notPriority) {
  40. this.queue.push(path);
  41. } else {
  42. this.priorityQueue.push(path);
  43. }
  44. }
  45. }
  46. visitMultiple(container, parent, listKey) {
  47. if (container.length === 0) return false;
  48. const queue = [];
  49. for (let key = 0; key < container.length; key++) {
  50. const node = container[key];
  51. if (node && this.shouldVisit(node)) {
  52. queue.push(this.create(parent, container, key, listKey));
  53. }
  54. }
  55. return this.visitQueue(queue);
  56. }
  57. visitSingle(node, key) {
  58. if (this.shouldVisit(node[key])) {
  59. return this.visitQueue([this.create(node, node, key)]);
  60. } else {
  61. return false;
  62. }
  63. }
  64. visitQueue(queue) {
  65. this.queue = queue;
  66. this.priorityQueue = [];
  67. const visited = new WeakSet();
  68. let stop = false;
  69. for (const path of queue) {
  70. path.resync();
  71. if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
  72. path.pushContext(this);
  73. }
  74. if (path.key === null) continue;
  75. const {
  76. node
  77. } = path;
  78. if (visited.has(node)) continue;
  79. if (node) visited.add(node);
  80. if (path.visit()) {
  81. stop = true;
  82. break;
  83. }
  84. if (this.priorityQueue.length) {
  85. stop = this.visitQueue(this.priorityQueue);
  86. this.priorityQueue = [];
  87. this.queue = queue;
  88. if (stop) break;
  89. }
  90. }
  91. for (const path of queue) {
  92. path.popContext();
  93. }
  94. this.queue = null;
  95. return stop;
  96. }
  97. visit(node, key) {
  98. const nodes = node[key];
  99. if (!nodes) return false;
  100. if (Array.isArray(nodes)) {
  101. return this.visitMultiple(nodes, node, key);
  102. } else {
  103. return this.visitSingle(node, key);
  104. }
  105. }
  106. }
  107. exports.default = TraversalContext;