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.

modification.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.insertBefore = insertBefore;
  6. exports._containerInsert = _containerInsert;
  7. exports._containerInsertBefore = _containerInsertBefore;
  8. exports._containerInsertAfter = _containerInsertAfter;
  9. exports.insertAfter = insertAfter;
  10. exports.updateSiblingKeys = updateSiblingKeys;
  11. exports._verifyNodeList = _verifyNodeList;
  12. exports.unshiftContainer = unshiftContainer;
  13. exports.pushContainer = pushContainer;
  14. exports.hoist = hoist;
  15. var _cache = require("../cache");
  16. var _hoister = require("./lib/hoister");
  17. var _index = require("./index");
  18. var t = require("@babel/types");
  19. function insertBefore(nodes_) {
  20. this._assertUnremoved();
  21. const nodes = this._verifyNodeList(nodes_);
  22. const {
  23. parentPath
  24. } = this;
  25. if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
  26. return parentPath.insertBefore(nodes);
  27. } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
  28. if (this.node) nodes.push(this.node);
  29. return this.replaceExpressionWithStatements(nodes);
  30. } else if (Array.isArray(this.container)) {
  31. return this._containerInsertBefore(nodes);
  32. } else if (this.isStatementOrBlock()) {
  33. const node = this.node;
  34. const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
  35. this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
  36. return this.unshiftContainer("body", nodes);
  37. } else {
  38. throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
  39. }
  40. }
  41. function _containerInsert(from, nodes) {
  42. this.updateSiblingKeys(from, nodes.length);
  43. const paths = [];
  44. this.container.splice(from, 0, ...nodes);
  45. for (let i = 0; i < nodes.length; i++) {
  46. const to = from + i;
  47. const path = this.getSibling(to);
  48. paths.push(path);
  49. if (this.context && this.context.queue) {
  50. path.pushContext(this.context);
  51. }
  52. }
  53. const contexts = this._getQueueContexts();
  54. for (const path of paths) {
  55. path.setScope();
  56. path.debug("Inserted.");
  57. for (const context of contexts) {
  58. context.maybeQueue(path, true);
  59. }
  60. }
  61. return paths;
  62. }
  63. function _containerInsertBefore(nodes) {
  64. return this._containerInsert(this.key, nodes);
  65. }
  66. function _containerInsertAfter(nodes) {
  67. return this._containerInsert(this.key + 1, nodes);
  68. }
  69. function insertAfter(nodes_) {
  70. this._assertUnremoved();
  71. const nodes = this._verifyNodeList(nodes_);
  72. const {
  73. parentPath
  74. } = this;
  75. if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
  76. return parentPath.insertAfter(nodes.map(node => {
  77. return t.isExpression(node) ? t.expressionStatement(node) : node;
  78. }));
  79. } else if (this.isNodeType("Expression") && !this.isJSXElement() && !parentPath.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
  80. if (this.node) {
  81. const node = this.node;
  82. let {
  83. scope
  84. } = this;
  85. if (scope.path.isPattern()) {
  86. t.assertExpression(node);
  87. this.replaceWith(t.callExpression(t.arrowFunctionExpression([], node), []));
  88. this.get("callee.body").insertAfter(nodes);
  89. return [this];
  90. }
  91. if (parentPath.isMethod({
  92. computed: true,
  93. key: node
  94. })) {
  95. scope = scope.parent;
  96. }
  97. const temp = scope.generateDeclaredUidIdentifier();
  98. nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), node)));
  99. nodes.push(t.expressionStatement(t.cloneNode(temp)));
  100. }
  101. return this.replaceExpressionWithStatements(nodes);
  102. } else if (Array.isArray(this.container)) {
  103. return this._containerInsertAfter(nodes);
  104. } else if (this.isStatementOrBlock()) {
  105. const node = this.node;
  106. const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
  107. this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : []));
  108. return this.pushContainer("body", nodes);
  109. } else {
  110. throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
  111. }
  112. }
  113. function updateSiblingKeys(fromIndex, incrementBy) {
  114. if (!this.parent) return;
  115. const paths = _cache.path.get(this.parent);
  116. for (const [, path] of paths) {
  117. if (path.key >= fromIndex) {
  118. path.key += incrementBy;
  119. }
  120. }
  121. }
  122. function _verifyNodeList(nodes) {
  123. if (!nodes) {
  124. return [];
  125. }
  126. if (!Array.isArray(nodes)) {
  127. nodes = [nodes];
  128. }
  129. for (let i = 0; i < nodes.length; i++) {
  130. const node = nodes[i];
  131. let msg;
  132. if (!node) {
  133. msg = "has falsy node";
  134. } else if (typeof node !== "object") {
  135. msg = "contains a non-object node";
  136. } else if (!node.type) {
  137. msg = "without a type";
  138. } else if (node instanceof _index.default) {
  139. msg = "has a NodePath when it expected a raw object";
  140. }
  141. if (msg) {
  142. const type = Array.isArray(node) ? "array" : typeof node;
  143. throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`);
  144. }
  145. }
  146. return nodes;
  147. }
  148. function unshiftContainer(listKey, nodes) {
  149. this._assertUnremoved();
  150. nodes = this._verifyNodeList(nodes);
  151. const path = _index.default.get({
  152. parentPath: this,
  153. parent: this.node,
  154. container: this.node[listKey],
  155. listKey,
  156. key: 0
  157. }).setContext(this.context);
  158. return path._containerInsertBefore(nodes);
  159. }
  160. function pushContainer(listKey, nodes) {
  161. this._assertUnremoved();
  162. const verifiedNodes = this._verifyNodeList(nodes);
  163. const container = this.node[listKey];
  164. const path = _index.default.get({
  165. parentPath: this,
  166. parent: this.node,
  167. container: container,
  168. listKey,
  169. key: container.length
  170. }).setContext(this.context);
  171. return path.replaceWithMultiple(verifiedNodes);
  172. }
  173. function hoist(scope = this.scope) {
  174. const hoister = new _hoister.default(this, scope);
  175. return hoister.run();
  176. }