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.

index.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = exports.SHOULD_SKIP = exports.SHOULD_STOP = exports.REMOVED = void 0;
  6. var virtualTypes = require("./lib/virtual-types");
  7. var _debug = require("debug");
  8. var _index = require("../index");
  9. var _scope = require("../scope");
  10. var t = require("@babel/types");
  11. var _cache = require("../cache");
  12. var _generator = require("@babel/generator");
  13. var NodePath_ancestry = require("./ancestry");
  14. var NodePath_inference = require("./inference");
  15. var NodePath_replacement = require("./replacement");
  16. var NodePath_evaluation = require("./evaluation");
  17. var NodePath_conversion = require("./conversion");
  18. var NodePath_introspection = require("./introspection");
  19. var NodePath_context = require("./context");
  20. var NodePath_removal = require("./removal");
  21. var NodePath_modification = require("./modification");
  22. var NodePath_family = require("./family");
  23. var NodePath_comments = require("./comments");
  24. const debug = _debug("babel");
  25. const REMOVED = 1 << 0;
  26. exports.REMOVED = REMOVED;
  27. const SHOULD_STOP = 1 << 1;
  28. exports.SHOULD_STOP = SHOULD_STOP;
  29. const SHOULD_SKIP = 1 << 2;
  30. exports.SHOULD_SKIP = SHOULD_SKIP;
  31. class NodePath {
  32. constructor(hub, parent) {
  33. this.contexts = [];
  34. this.state = null;
  35. this.opts = null;
  36. this._traverseFlags = 0;
  37. this.skipKeys = null;
  38. this.parentPath = null;
  39. this.container = null;
  40. this.listKey = null;
  41. this.key = null;
  42. this.node = null;
  43. this.type = null;
  44. this.parent = parent;
  45. this.hub = hub;
  46. this.data = null;
  47. this.context = null;
  48. this.scope = null;
  49. }
  50. static get({
  51. hub,
  52. parentPath,
  53. parent,
  54. container,
  55. listKey,
  56. key
  57. }) {
  58. if (!hub && parentPath) {
  59. hub = parentPath.hub;
  60. }
  61. if (!parent) {
  62. throw new Error("To get a node path the parent needs to exist");
  63. }
  64. const targetNode = container[key];
  65. let paths = _cache.path.get(parent);
  66. if (!paths) {
  67. paths = new Map();
  68. _cache.path.set(parent, paths);
  69. }
  70. let path = paths.get(targetNode);
  71. if (!path) {
  72. path = new NodePath(hub, parent);
  73. if (targetNode) paths.set(targetNode, path);
  74. }
  75. path.setup(parentPath, container, listKey, key);
  76. return path;
  77. }
  78. getScope(scope) {
  79. return this.isScope() ? new _scope.default(this) : scope;
  80. }
  81. setData(key, val) {
  82. if (this.data == null) {
  83. this.data = Object.create(null);
  84. }
  85. return this.data[key] = val;
  86. }
  87. getData(key, def) {
  88. if (this.data == null) {
  89. this.data = Object.create(null);
  90. }
  91. let val = this.data[key];
  92. if (val === undefined && def !== undefined) val = this.data[key] = def;
  93. return val;
  94. }
  95. buildCodeFrameError(msg, Error = SyntaxError) {
  96. return this.hub.buildError(this.node, msg, Error);
  97. }
  98. traverse(visitor, state) {
  99. (0, _index.default)(this.node, visitor, this.scope, state, this);
  100. }
  101. set(key, node) {
  102. t.validate(this.node, key, node);
  103. this.node[key] = node;
  104. }
  105. getPathLocation() {
  106. const parts = [];
  107. let path = this;
  108. do {
  109. let key = path.key;
  110. if (path.inList) key = `${path.listKey}[${key}]`;
  111. parts.unshift(key);
  112. } while (path = path.parentPath);
  113. return parts.join(".");
  114. }
  115. debug(message) {
  116. if (!debug.enabled) return;
  117. debug(`${this.getPathLocation()} ${this.type}: ${message}`);
  118. }
  119. toString() {
  120. return (0, _generator.default)(this.node).code;
  121. }
  122. get inList() {
  123. return !!this.listKey;
  124. }
  125. set inList(inList) {
  126. if (!inList) {
  127. this.listKey = null;
  128. }
  129. }
  130. get parentKey() {
  131. return this.listKey || this.key;
  132. }
  133. get shouldSkip() {
  134. return !!(this._traverseFlags & SHOULD_SKIP);
  135. }
  136. set shouldSkip(v) {
  137. if (v) {
  138. this._traverseFlags |= SHOULD_SKIP;
  139. } else {
  140. this._traverseFlags &= ~SHOULD_SKIP;
  141. }
  142. }
  143. get shouldStop() {
  144. return !!(this._traverseFlags & SHOULD_STOP);
  145. }
  146. set shouldStop(v) {
  147. if (v) {
  148. this._traverseFlags |= SHOULD_STOP;
  149. } else {
  150. this._traverseFlags &= ~SHOULD_STOP;
  151. }
  152. }
  153. get removed() {
  154. return !!(this._traverseFlags & REMOVED);
  155. }
  156. set removed(v) {
  157. if (v) {
  158. this._traverseFlags |= REMOVED;
  159. } else {
  160. this._traverseFlags &= ~REMOVED;
  161. }
  162. }
  163. }
  164. Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
  165. for (const type of t.TYPES) {
  166. const typeKey = `is${type}`;
  167. const fn = t[typeKey];
  168. NodePath.prototype[typeKey] = function (opts) {
  169. return fn(this.node, opts);
  170. };
  171. NodePath.prototype[`assert${type}`] = function (opts) {
  172. if (!fn(this.node, opts)) {
  173. throw new TypeError(`Expected node path of type ${type}`);
  174. }
  175. };
  176. }
  177. for (const type of Object.keys(virtualTypes)) {
  178. if (type[0] === "_") continue;
  179. if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type);
  180. const virtualType = virtualTypes[type];
  181. NodePath.prototype[`is${type}`] = function (opts) {
  182. return virtualType.checkPath(this, opts);
  183. };
  184. }
  185. var _default = NodePath;
  186. exports.default = _default;