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 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.call = call;
  6. exports._call = _call;
  7. exports.isBlacklisted = exports.isDenylisted = isDenylisted;
  8. exports.visit = visit;
  9. exports.skip = skip;
  10. exports.skipKey = skipKey;
  11. exports.stop = stop;
  12. exports.setScope = setScope;
  13. exports.setContext = setContext;
  14. exports.resync = resync;
  15. exports._resyncParent = _resyncParent;
  16. exports._resyncKey = _resyncKey;
  17. exports._resyncList = _resyncList;
  18. exports._resyncRemoved = _resyncRemoved;
  19. exports.popContext = popContext;
  20. exports.pushContext = pushContext;
  21. exports.setup = setup;
  22. exports.setKey = setKey;
  23. exports.requeue = requeue;
  24. exports._getQueueContexts = _getQueueContexts;
  25. var _index = require("../index");
  26. var _index2 = require("./index");
  27. function call(key) {
  28. const opts = this.opts;
  29. this.debug(key);
  30. if (this.node) {
  31. if (this._call(opts[key])) return true;
  32. }
  33. if (this.node) {
  34. return this._call(opts[this.node.type] && opts[this.node.type][key]);
  35. }
  36. return false;
  37. }
  38. function _call(fns) {
  39. if (!fns) return false;
  40. for (const fn of fns) {
  41. if (!fn) continue;
  42. const node = this.node;
  43. if (!node) return true;
  44. const ret = fn.call(this.state, this, this.state);
  45. if (ret && typeof ret === "object" && typeof ret.then === "function") {
  46. throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
  47. }
  48. if (ret) {
  49. throw new Error(`Unexpected return value from visitor method ${fn}`);
  50. }
  51. if (this.node !== node) return true;
  52. if (this._traverseFlags > 0) return true;
  53. }
  54. return false;
  55. }
  56. function isDenylisted() {
  57. var _this$opts$denylist;
  58. const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
  59. return denylist && denylist.indexOf(this.node.type) > -1;
  60. }
  61. function visit() {
  62. if (!this.node) {
  63. return false;
  64. }
  65. if (this.isDenylisted()) {
  66. return false;
  67. }
  68. if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
  69. return false;
  70. }
  71. if (this.shouldSkip || this.call("enter") || this.shouldSkip) {
  72. this.debug("Skip...");
  73. return this.shouldStop;
  74. }
  75. this.debug("Recursing into...");
  76. _index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
  77. this.call("exit");
  78. return this.shouldStop;
  79. }
  80. function skip() {
  81. this.shouldSkip = true;
  82. }
  83. function skipKey(key) {
  84. if (this.skipKeys == null) {
  85. this.skipKeys = {};
  86. }
  87. this.skipKeys[key] = true;
  88. }
  89. function stop() {
  90. this._traverseFlags |= _index2.SHOULD_SKIP | _index2.SHOULD_STOP;
  91. }
  92. function setScope() {
  93. if (this.opts && this.opts.noScope) return;
  94. let path = this.parentPath;
  95. if (this.key === "key" && path.isMethod()) path = path.parentPath;
  96. let target;
  97. while (path && !target) {
  98. if (path.opts && path.opts.noScope) return;
  99. target = path.scope;
  100. path = path.parentPath;
  101. }
  102. this.scope = this.getScope(target);
  103. if (this.scope) this.scope.init();
  104. }
  105. function setContext(context) {
  106. if (this.skipKeys != null) {
  107. this.skipKeys = {};
  108. }
  109. this._traverseFlags = 0;
  110. if (context) {
  111. this.context = context;
  112. this.state = context.state;
  113. this.opts = context.opts;
  114. }
  115. this.setScope();
  116. return this;
  117. }
  118. function resync() {
  119. if (this.removed) return;
  120. this._resyncParent();
  121. this._resyncList();
  122. this._resyncKey();
  123. }
  124. function _resyncParent() {
  125. if (this.parentPath) {
  126. this.parent = this.parentPath.node;
  127. }
  128. }
  129. function _resyncKey() {
  130. if (!this.container) return;
  131. if (this.node === this.container[this.key]) return;
  132. if (Array.isArray(this.container)) {
  133. for (let i = 0; i < this.container.length; i++) {
  134. if (this.container[i] === this.node) {
  135. return this.setKey(i);
  136. }
  137. }
  138. } else {
  139. for (const key of Object.keys(this.container)) {
  140. if (this.container[key] === this.node) {
  141. return this.setKey(key);
  142. }
  143. }
  144. }
  145. this.key = null;
  146. }
  147. function _resyncList() {
  148. if (!this.parent || !this.inList) return;
  149. const newContainer = this.parent[this.listKey];
  150. if (this.container === newContainer) return;
  151. this.container = newContainer || null;
  152. }
  153. function _resyncRemoved() {
  154. if (this.key == null || !this.container || this.container[this.key] !== this.node) {
  155. this._markRemoved();
  156. }
  157. }
  158. function popContext() {
  159. this.contexts.pop();
  160. if (this.contexts.length > 0) {
  161. this.setContext(this.contexts[this.contexts.length - 1]);
  162. } else {
  163. this.setContext(undefined);
  164. }
  165. }
  166. function pushContext(context) {
  167. this.contexts.push(context);
  168. this.setContext(context);
  169. }
  170. function setup(parentPath, container, listKey, key) {
  171. this.listKey = listKey;
  172. this.container = container;
  173. this.parentPath = parentPath || this.parentPath;
  174. this.setKey(key);
  175. }
  176. function setKey(key) {
  177. var _this$node;
  178. this.key = key;
  179. this.node = this.container[this.key];
  180. this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
  181. }
  182. function requeue(pathToQueue = this) {
  183. if (pathToQueue.removed) return;
  184. ;
  185. const contexts = this.contexts;
  186. for (const context of contexts) {
  187. context.maybeQueue(pathToQueue);
  188. }
  189. }
  190. function _getQueueContexts() {
  191. let path = this;
  192. let contexts = this.contexts;
  193. while (!contexts.length) {
  194. path = path.parentPath;
  195. if (!path) break;
  196. contexts = path.contexts;
  197. }
  198. return contexts;
  199. }