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.

whitespace.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.list = exports.nodes = void 0;
  6. var t = require("@babel/types");
  7. function crawl(node, state = {}) {
  8. if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
  9. crawl(node.object, state);
  10. if (node.computed) crawl(node.property, state);
  11. } else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
  12. crawl(node.left, state);
  13. crawl(node.right, state);
  14. } else if (t.isCallExpression(node) || t.isOptionalCallExpression(node)) {
  15. state.hasCall = true;
  16. crawl(node.callee, state);
  17. } else if (t.isFunction(node)) {
  18. state.hasFunction = true;
  19. } else if (t.isIdentifier(node)) {
  20. state.hasHelper = state.hasHelper || isHelper(node.callee);
  21. }
  22. return state;
  23. }
  24. function isHelper(node) {
  25. if (t.isMemberExpression(node)) {
  26. return isHelper(node.object) || isHelper(node.property);
  27. } else if (t.isIdentifier(node)) {
  28. return node.name === "require" || node.name[0] === "_";
  29. } else if (t.isCallExpression(node)) {
  30. return isHelper(node.callee);
  31. } else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
  32. return t.isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right);
  33. } else {
  34. return false;
  35. }
  36. }
  37. function isType(node) {
  38. return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) || t.isIdentifier(node) || t.isMemberExpression(node);
  39. }
  40. const nodes = {
  41. AssignmentExpression(node) {
  42. const state = crawl(node.right);
  43. if (state.hasCall && state.hasHelper || state.hasFunction) {
  44. return {
  45. before: state.hasFunction,
  46. after: true
  47. };
  48. }
  49. },
  50. SwitchCase(node, parent) {
  51. return {
  52. before: !!node.consequent.length || parent.cases[0] === node,
  53. after: !node.consequent.length && parent.cases[parent.cases.length - 1] === node
  54. };
  55. },
  56. LogicalExpression(node) {
  57. if (t.isFunction(node.left) || t.isFunction(node.right)) {
  58. return {
  59. after: true
  60. };
  61. }
  62. },
  63. Literal(node) {
  64. if (t.isStringLiteral(node) && node.value === "use strict") {
  65. return {
  66. after: true
  67. };
  68. }
  69. },
  70. CallExpression(node) {
  71. if (t.isFunction(node.callee) || isHelper(node)) {
  72. return {
  73. before: true,
  74. after: true
  75. };
  76. }
  77. },
  78. OptionalCallExpression(node) {
  79. if (t.isFunction(node.callee)) {
  80. return {
  81. before: true,
  82. after: true
  83. };
  84. }
  85. },
  86. VariableDeclaration(node) {
  87. for (let i = 0; i < node.declarations.length; i++) {
  88. const declar = node.declarations[i];
  89. let enabled = isHelper(declar.id) && !isType(declar.init);
  90. if (!enabled) {
  91. const state = crawl(declar.init);
  92. enabled = isHelper(declar.init) && state.hasCall || state.hasFunction;
  93. }
  94. if (enabled) {
  95. return {
  96. before: true,
  97. after: true
  98. };
  99. }
  100. }
  101. },
  102. IfStatement(node) {
  103. if (t.isBlockStatement(node.consequent)) {
  104. return {
  105. before: true,
  106. after: true
  107. };
  108. }
  109. }
  110. };
  111. exports.nodes = nodes;
  112. nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (node, parent) {
  113. if (parent.properties[0] === node) {
  114. return {
  115. before: true
  116. };
  117. }
  118. };
  119. nodes.ObjectTypeCallProperty = function (node, parent) {
  120. var _parent$properties;
  121. if (parent.callProperties[0] === node && !((_parent$properties = parent.properties) != null && _parent$properties.length)) {
  122. return {
  123. before: true
  124. };
  125. }
  126. };
  127. nodes.ObjectTypeIndexer = function (node, parent) {
  128. var _parent$properties2, _parent$callPropertie;
  129. if (parent.indexers[0] === node && !((_parent$properties2 = parent.properties) != null && _parent$properties2.length) && !((_parent$callPropertie = parent.callProperties) != null && _parent$callPropertie.length)) {
  130. return {
  131. before: true
  132. };
  133. }
  134. };
  135. nodes.ObjectTypeInternalSlot = function (node, parent) {
  136. var _parent$properties3, _parent$callPropertie2, _parent$indexers;
  137. if (parent.internalSlots[0] === node && !((_parent$properties3 = parent.properties) != null && _parent$properties3.length) && !((_parent$callPropertie2 = parent.callProperties) != null && _parent$callPropertie2.length) && !((_parent$indexers = parent.indexers) != null && _parent$indexers.length)) {
  138. return {
  139. before: true
  140. };
  141. }
  142. };
  143. const list = {
  144. VariableDeclaration(node) {
  145. return node.declarations.map(decl => decl.init);
  146. },
  147. ArrayExpression(node) {
  148. return node.elements;
  149. },
  150. ObjectExpression(node) {
  151. return node.properties;
  152. }
  153. };
  154. exports.list = list;
  155. [["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) {
  156. if (typeof amounts === "boolean") {
  157. amounts = {
  158. after: amounts,
  159. before: amounts
  160. };
  161. }
  162. [type].concat(t.FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) {
  163. nodes[type] = function () {
  164. return amounts;
  165. };
  166. });
  167. });