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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var t = require('@babel/types');
  4. function _interopNamespace(e) {
  5. if (e && e.__esModule) return e;
  6. var n = Object.create(null);
  7. if (e) {
  8. Object.keys(e).forEach(function (k) {
  9. if (k !== 'default') {
  10. var d = Object.getOwnPropertyDescriptor(e, k);
  11. Object.defineProperty(n, k, d.get ? d : {
  12. enumerable: true,
  13. get: function () {
  14. return e[k];
  15. }
  16. });
  17. }
  18. });
  19. }
  20. n['default'] = e;
  21. return Object.freeze(n);
  22. }
  23. var t__namespace = /*#__PURE__*/_interopNamespace(t);
  24. function willPathCastToBoolean(path) {
  25. const maybeWrapped = path;
  26. const {
  27. node,
  28. parentPath
  29. } = maybeWrapped;
  30. if (parentPath.isLogicalExpression()) {
  31. const {
  32. operator,
  33. right
  34. } = parentPath.node;
  35. if (operator === "&&" || operator === "||" || operator === "??" && node === right) {
  36. return willPathCastToBoolean(parentPath);
  37. }
  38. }
  39. if (parentPath.isSequenceExpression()) {
  40. const {
  41. expressions
  42. } = parentPath.node;
  43. if (expressions[expressions.length - 1] === node) {
  44. return willPathCastToBoolean(parentPath);
  45. } else {
  46. return true;
  47. }
  48. }
  49. return parentPath.isConditional({
  50. test: node
  51. }) || parentPath.isUnaryExpression({
  52. operator: "!"
  53. }) || parentPath.isLoop({
  54. test: node
  55. });
  56. }
  57. class AssignmentMemoiser {
  58. constructor() {
  59. this._map = void 0;
  60. this._map = new WeakMap();
  61. }
  62. has(key) {
  63. return this._map.has(key);
  64. }
  65. get(key) {
  66. if (!this.has(key)) return;
  67. const record = this._map.get(key);
  68. const {
  69. value
  70. } = record;
  71. record.count--;
  72. if (record.count === 0) {
  73. return t__namespace.assignmentExpression("=", value, key);
  74. }
  75. return value;
  76. }
  77. set(key, value, count) {
  78. return this._map.set(key, {
  79. count,
  80. value
  81. });
  82. }
  83. }
  84. function toNonOptional(path, base) {
  85. const {
  86. node
  87. } = path;
  88. if (path.isOptionalMemberExpression()) {
  89. return t__namespace.memberExpression(base, node.property, node.computed);
  90. }
  91. if (path.isOptionalCallExpression()) {
  92. const callee = path.get("callee");
  93. if (path.node.optional && callee.isOptionalMemberExpression()) {
  94. const {
  95. object
  96. } = callee.node;
  97. const context = path.scope.maybeGenerateMemoised(object) || object;
  98. callee.get("object").replaceWith(t__namespace.assignmentExpression("=", context, object));
  99. return t__namespace.callExpression(t__namespace.memberExpression(base, t__namespace.identifier("call")), [context, ...node.arguments]);
  100. }
  101. return t__namespace.callExpression(base, node.arguments);
  102. }
  103. return path.node;
  104. }
  105. function isInDetachedTree(path) {
  106. while (path) {
  107. if (path.isProgram()) break;
  108. const {
  109. parentPath,
  110. container,
  111. listKey
  112. } = path;
  113. const parentNode = parentPath.node;
  114. if (listKey) {
  115. if (container !== parentNode[listKey]) return true;
  116. } else {
  117. if (container !== parentNode) return true;
  118. }
  119. path = parentPath;
  120. }
  121. return false;
  122. }
  123. const handle = {
  124. memoise() {},
  125. handle(member, noDocumentAll) {
  126. const {
  127. node,
  128. parent,
  129. parentPath,
  130. scope
  131. } = member;
  132. if (member.isOptionalMemberExpression()) {
  133. if (isInDetachedTree(member)) return;
  134. const endPath = member.find(({
  135. node,
  136. parent,
  137. parentPath
  138. }) => {
  139. if (parentPath.isOptionalMemberExpression()) {
  140. return parent.optional || parent.object !== node;
  141. }
  142. if (parentPath.isOptionalCallExpression()) {
  143. return node !== member.node && parent.optional || parent.callee !== node;
  144. }
  145. return true;
  146. });
  147. if (scope.path.isPattern()) {
  148. endPath.replaceWith(t__namespace.callExpression(t__namespace.arrowFunctionExpression([], endPath.node), []));
  149. return;
  150. }
  151. const willEndPathCastToBoolean = willPathCastToBoolean(endPath);
  152. const rootParentPath = endPath.parentPath;
  153. if (rootParentPath.isUpdateExpression({
  154. argument: node
  155. }) || rootParentPath.isAssignmentExpression({
  156. left: node
  157. })) {
  158. throw member.buildCodeFrameError(`can't handle assignment`);
  159. }
  160. const isDeleteOperation = rootParentPath.isUnaryExpression({
  161. operator: "delete"
  162. });
  163. if (isDeleteOperation && endPath.isOptionalMemberExpression() && endPath.get("property").isPrivateName()) {
  164. throw member.buildCodeFrameError(`can't delete a private class element`);
  165. }
  166. let startingOptional = member;
  167. for (;;) {
  168. if (startingOptional.isOptionalMemberExpression()) {
  169. if (startingOptional.node.optional) break;
  170. startingOptional = startingOptional.get("object");
  171. continue;
  172. } else if (startingOptional.isOptionalCallExpression()) {
  173. if (startingOptional.node.optional) break;
  174. startingOptional = startingOptional.get("callee");
  175. continue;
  176. }
  177. throw new Error(`Internal error: unexpected ${startingOptional.node.type}`);
  178. }
  179. const startingProp = startingOptional.isOptionalMemberExpression() ? "object" : "callee";
  180. const startingNode = startingOptional.node[startingProp];
  181. const baseNeedsMemoised = scope.maybeGenerateMemoised(startingNode);
  182. const baseRef = baseNeedsMemoised != null ? baseNeedsMemoised : startingNode;
  183. const parentIsOptionalCall = parentPath.isOptionalCallExpression({
  184. callee: node
  185. });
  186. const parentIsCall = parentPath.isCallExpression({
  187. callee: node
  188. });
  189. startingOptional.replaceWith(toNonOptional(startingOptional, baseRef));
  190. if (parentIsOptionalCall) {
  191. if (parent.optional) {
  192. parentPath.replaceWith(this.optionalCall(member, parent.arguments));
  193. } else {
  194. parentPath.replaceWith(this.call(member, parent.arguments));
  195. }
  196. } else if (parentIsCall) {
  197. member.replaceWith(this.boundGet(member));
  198. } else {
  199. member.replaceWith(this.get(member));
  200. }
  201. let regular = member.node;
  202. for (let current = member; current !== endPath;) {
  203. const {
  204. parentPath
  205. } = current;
  206. if (parentPath === endPath && parentIsOptionalCall && parent.optional) {
  207. regular = parentPath.node;
  208. break;
  209. }
  210. regular = toNonOptional(parentPath, regular);
  211. current = parentPath;
  212. }
  213. let context;
  214. const endParentPath = endPath.parentPath;
  215. if (t__namespace.isMemberExpression(regular) && endParentPath.isOptionalCallExpression({
  216. callee: endPath.node,
  217. optional: true
  218. })) {
  219. const {
  220. object
  221. } = regular;
  222. context = member.scope.maybeGenerateMemoised(object);
  223. if (context) {
  224. regular.object = t__namespace.assignmentExpression("=", context, object);
  225. }
  226. }
  227. let replacementPath = endPath;
  228. if (isDeleteOperation) {
  229. replacementPath = endParentPath;
  230. regular = endParentPath.node;
  231. }
  232. const baseMemoised = baseNeedsMemoised ? t__namespace.assignmentExpression("=", t__namespace.cloneNode(baseRef), t__namespace.cloneNode(startingNode)) : t__namespace.cloneNode(baseRef);
  233. if (willEndPathCastToBoolean) {
  234. let nonNullishCheck;
  235. if (noDocumentAll) {
  236. nonNullishCheck = t__namespace.binaryExpression("!=", baseMemoised, t__namespace.nullLiteral());
  237. } else {
  238. nonNullishCheck = t__namespace.logicalExpression("&&", t__namespace.binaryExpression("!==", baseMemoised, t__namespace.nullLiteral()), t__namespace.binaryExpression("!==", t__namespace.cloneNode(baseRef), scope.buildUndefinedNode()));
  239. }
  240. replacementPath.replaceWith(t__namespace.logicalExpression("&&", nonNullishCheck, regular));
  241. } else {
  242. let nullishCheck;
  243. if (noDocumentAll) {
  244. nullishCheck = t__namespace.binaryExpression("==", baseMemoised, t__namespace.nullLiteral());
  245. } else {
  246. nullishCheck = t__namespace.logicalExpression("||", t__namespace.binaryExpression("===", baseMemoised, t__namespace.nullLiteral()), t__namespace.binaryExpression("===", t__namespace.cloneNode(baseRef), scope.buildUndefinedNode()));
  247. }
  248. replacementPath.replaceWith(t__namespace.conditionalExpression(nullishCheck, isDeleteOperation ? t__namespace.booleanLiteral(true) : scope.buildUndefinedNode(), regular));
  249. }
  250. if (context) {
  251. const endParent = endParentPath.node;
  252. endParentPath.replaceWith(t__namespace.optionalCallExpression(t__namespace.optionalMemberExpression(endParent.callee, t__namespace.identifier("call"), false, true), [t__namespace.cloneNode(context), ...endParent.arguments], false));
  253. }
  254. return;
  255. }
  256. if (parentPath.isUpdateExpression({
  257. argument: node
  258. })) {
  259. if (this.simpleSet) {
  260. member.replaceWith(this.simpleSet(member));
  261. return;
  262. }
  263. const {
  264. operator,
  265. prefix
  266. } = parent;
  267. this.memoise(member, 2);
  268. const value = t__namespace.binaryExpression(operator[0], t__namespace.unaryExpression("+", this.get(member)), t__namespace.numericLiteral(1));
  269. if (prefix) {
  270. parentPath.replaceWith(this.set(member, value));
  271. } else {
  272. const {
  273. scope
  274. } = member;
  275. const ref = scope.generateUidIdentifierBasedOnNode(node);
  276. scope.push({
  277. id: ref
  278. });
  279. value.left = t__namespace.assignmentExpression("=", t__namespace.cloneNode(ref), value.left);
  280. parentPath.replaceWith(t__namespace.sequenceExpression([this.set(member, value), t__namespace.cloneNode(ref)]));
  281. }
  282. return;
  283. }
  284. if (parentPath.isAssignmentExpression({
  285. left: node
  286. })) {
  287. if (this.simpleSet) {
  288. member.replaceWith(this.simpleSet(member));
  289. return;
  290. }
  291. const {
  292. operator,
  293. right: value
  294. } = parent;
  295. if (operator === "=") {
  296. parentPath.replaceWith(this.set(member, value));
  297. } else {
  298. const operatorTrunc = operator.slice(0, -1);
  299. if (t__namespace.LOGICAL_OPERATORS.includes(operatorTrunc)) {
  300. this.memoise(member, 1);
  301. parentPath.replaceWith(t__namespace.logicalExpression(operatorTrunc, this.get(member), this.set(member, value)));
  302. } else {
  303. this.memoise(member, 2);
  304. parentPath.replaceWith(this.set(member, t__namespace.binaryExpression(operatorTrunc, this.get(member), value)));
  305. }
  306. }
  307. return;
  308. }
  309. if (parentPath.isCallExpression({
  310. callee: node
  311. })) {
  312. parentPath.replaceWith(this.call(member, parent.arguments));
  313. return;
  314. }
  315. if (parentPath.isOptionalCallExpression({
  316. callee: node
  317. })) {
  318. if (scope.path.isPattern()) {
  319. parentPath.replaceWith(t__namespace.callExpression(t__namespace.arrowFunctionExpression([], parentPath.node), []));
  320. return;
  321. }
  322. parentPath.replaceWith(this.optionalCall(member, parent.arguments));
  323. return;
  324. }
  325. if (parentPath.isForXStatement({
  326. left: node
  327. }) || parentPath.isObjectProperty({
  328. value: node
  329. }) && parentPath.parentPath.isObjectPattern() || parentPath.isAssignmentPattern({
  330. left: node
  331. }) && parentPath.parentPath.isObjectProperty({
  332. value: parent
  333. }) && parentPath.parentPath.parentPath.isObjectPattern() || parentPath.isArrayPattern() || parentPath.isAssignmentPattern({
  334. left: node
  335. }) && parentPath.parentPath.isArrayPattern() || parentPath.isRestElement()) {
  336. member.replaceWith(this.destructureSet(member));
  337. return;
  338. }
  339. if (parentPath.isTaggedTemplateExpression()) {
  340. member.replaceWith(this.boundGet(member));
  341. } else {
  342. member.replaceWith(this.get(member));
  343. }
  344. }
  345. };
  346. function memberExpressionToFunctions(path, visitor, state) {
  347. path.traverse(visitor, Object.assign({}, handle, state, {
  348. memoiser: new AssignmentMemoiser()
  349. }));
  350. }
  351. exports.default = memberExpressionToFunctions;
  352. //# sourceMappingURL=index.js.map