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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.skipAllButComputedKey = skipAllButComputedKey;
  6. exports.default = exports.environmentVisitor = void 0;
  7. var _traverse = require("@babel/traverse");
  8. var _helperMemberExpressionToFunctions = require("@babel/helper-member-expression-to-functions");
  9. var _helperOptimiseCallExpression = require("@babel/helper-optimise-call-expression");
  10. var t = require("@babel/types");
  11. function getPrototypeOfExpression(objectRef, isStatic, file, isPrivateMethod) {
  12. objectRef = t.cloneNode(objectRef);
  13. const targetRef = isStatic || isPrivateMethod ? objectRef : t.memberExpression(objectRef, t.identifier("prototype"));
  14. return t.callExpression(file.addHelper("getPrototypeOf"), [targetRef]);
  15. }
  16. function skipAllButComputedKey(path) {
  17. if (!path.node.computed) {
  18. path.skip();
  19. return;
  20. }
  21. const keys = t.VISITOR_KEYS[path.type];
  22. for (const key of keys) {
  23. if (key !== "key") path.skipKey(key);
  24. }
  25. }
  26. const environmentVisitor = {
  27. [`${t.staticBlock ? "StaticBlock|" : ""}ClassPrivateProperty|TypeAnnotation`](path) {
  28. path.skip();
  29. },
  30. Function(path) {
  31. if (path.isMethod()) return;
  32. if (path.isArrowFunctionExpression()) return;
  33. path.skip();
  34. },
  35. "Method|ClassProperty"(path) {
  36. skipAllButComputedKey(path);
  37. }
  38. };
  39. exports.environmentVisitor = environmentVisitor;
  40. const visitor = _traverse.default.visitors.merge([environmentVisitor, {
  41. Super(path, state) {
  42. const {
  43. node,
  44. parentPath
  45. } = path;
  46. if (!parentPath.isMemberExpression({
  47. object: node
  48. })) return;
  49. state.handle(parentPath);
  50. }
  51. }]);
  52. const unshadowSuperBindingVisitor = _traverse.default.visitors.merge([environmentVisitor, {
  53. Scopable(path, {
  54. refName
  55. }) {
  56. const binding = path.scope.getOwnBinding(refName);
  57. if (binding && binding.identifier.name === refName) {
  58. path.scope.rename(refName);
  59. }
  60. }
  61. }]);
  62. const specHandlers = {
  63. memoise(superMember, count) {
  64. const {
  65. scope,
  66. node
  67. } = superMember;
  68. const {
  69. computed,
  70. property
  71. } = node;
  72. if (!computed) {
  73. return;
  74. }
  75. const memo = scope.maybeGenerateMemoised(property);
  76. if (!memo) {
  77. return;
  78. }
  79. this.memoiser.set(property, memo, count);
  80. },
  81. prop(superMember) {
  82. const {
  83. computed,
  84. property
  85. } = superMember.node;
  86. if (this.memoiser.has(property)) {
  87. return t.cloneNode(this.memoiser.get(property));
  88. }
  89. if (computed) {
  90. return t.cloneNode(property);
  91. }
  92. return t.stringLiteral(property.name);
  93. },
  94. get(superMember) {
  95. return this._get(superMember, this._getThisRefs());
  96. },
  97. _get(superMember, thisRefs) {
  98. const proto = getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file, this.isPrivateMethod);
  99. return t.callExpression(this.file.addHelper("get"), [thisRefs.memo ? t.sequenceExpression([thisRefs.memo, proto]) : proto, this.prop(superMember), thisRefs.this]);
  100. },
  101. _getThisRefs() {
  102. if (!this.isDerivedConstructor) {
  103. return {
  104. this: t.thisExpression()
  105. };
  106. }
  107. const thisRef = this.scope.generateDeclaredUidIdentifier("thisSuper");
  108. return {
  109. memo: t.assignmentExpression("=", thisRef, t.thisExpression()),
  110. this: t.cloneNode(thisRef)
  111. };
  112. },
  113. set(superMember, value) {
  114. const thisRefs = this._getThisRefs();
  115. const proto = getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file, this.isPrivateMethod);
  116. return t.callExpression(this.file.addHelper("set"), [thisRefs.memo ? t.sequenceExpression([thisRefs.memo, proto]) : proto, this.prop(superMember), value, thisRefs.this, t.booleanLiteral(superMember.isInStrictMode())]);
  117. },
  118. destructureSet(superMember) {
  119. throw superMember.buildCodeFrameError(`Destructuring to a super field is not supported yet.`);
  120. },
  121. call(superMember, args) {
  122. const thisRefs = this._getThisRefs();
  123. return (0, _helperOptimiseCallExpression.default)(this._get(superMember, thisRefs), t.cloneNode(thisRefs.this), args, false);
  124. },
  125. optionalCall(superMember, args) {
  126. const thisRefs = this._getThisRefs();
  127. return (0, _helperOptimiseCallExpression.default)(this._get(superMember, thisRefs), t.cloneNode(thisRefs.this), args, true);
  128. }
  129. };
  130. const looseHandlers = Object.assign({}, specHandlers, {
  131. prop(superMember) {
  132. const {
  133. property
  134. } = superMember.node;
  135. if (this.memoiser.has(property)) {
  136. return t.cloneNode(this.memoiser.get(property));
  137. }
  138. return t.cloneNode(property);
  139. },
  140. get(superMember) {
  141. const {
  142. isStatic,
  143. getSuperRef
  144. } = this;
  145. const {
  146. computed
  147. } = superMember.node;
  148. const prop = this.prop(superMember);
  149. let object;
  150. if (isStatic) {
  151. var _getSuperRef;
  152. object = (_getSuperRef = getSuperRef()) != null ? _getSuperRef : t.memberExpression(t.identifier("Function"), t.identifier("prototype"));
  153. } else {
  154. var _getSuperRef2;
  155. object = t.memberExpression((_getSuperRef2 = getSuperRef()) != null ? _getSuperRef2 : t.identifier("Object"), t.identifier("prototype"));
  156. }
  157. return t.memberExpression(object, prop, computed);
  158. },
  159. set(superMember, value) {
  160. const {
  161. computed
  162. } = superMember.node;
  163. const prop = this.prop(superMember);
  164. return t.assignmentExpression("=", t.memberExpression(t.thisExpression(), prop, computed), value);
  165. },
  166. destructureSet(superMember) {
  167. const {
  168. computed
  169. } = superMember.node;
  170. const prop = this.prop(superMember);
  171. return t.memberExpression(t.thisExpression(), prop, computed);
  172. },
  173. call(superMember, args) {
  174. return (0, _helperOptimiseCallExpression.default)(this.get(superMember), t.thisExpression(), args, false);
  175. },
  176. optionalCall(superMember, args) {
  177. return (0, _helperOptimiseCallExpression.default)(this.get(superMember), t.thisExpression(), args, true);
  178. }
  179. });
  180. class ReplaceSupers {
  181. constructor(opts) {
  182. var _opts$constantSuper;
  183. const path = opts.methodPath;
  184. this.methodPath = path;
  185. this.isDerivedConstructor = path.isClassMethod({
  186. kind: "constructor"
  187. }) && !!opts.superRef;
  188. this.isStatic = path.isObjectMethod() || path.node.static || (path.isStaticBlock == null ? void 0 : path.isStaticBlock());
  189. this.isPrivateMethod = path.isPrivate() && path.isMethod();
  190. this.file = opts.file;
  191. this.constantSuper = (_opts$constantSuper = opts.constantSuper) != null ? _opts$constantSuper : opts.isLoose;
  192. this.opts = opts;
  193. }
  194. getObjectRef() {
  195. return t.cloneNode(this.opts.objectRef || this.opts.getObjectRef());
  196. }
  197. getSuperRef() {
  198. if (this.opts.superRef) return t.cloneNode(this.opts.superRef);
  199. if (this.opts.getSuperRef) return t.cloneNode(this.opts.getSuperRef());
  200. }
  201. replace() {
  202. if (this.opts.refToPreserve) {
  203. this.methodPath.traverse(unshadowSuperBindingVisitor, {
  204. refName: this.opts.refToPreserve.name
  205. });
  206. }
  207. const handler = this.constantSuper ? looseHandlers : specHandlers;
  208. (0, _helperMemberExpressionToFunctions.default)(this.methodPath, visitor, Object.assign({
  209. file: this.file,
  210. scope: this.methodPath.scope,
  211. isDerivedConstructor: this.isDerivedConstructor,
  212. isStatic: this.isStatic,
  213. isPrivateMethod: this.isPrivateMethod,
  214. getObjectRef: this.getObjectRef.bind(this),
  215. getSuperRef: this.getSuperRef.bind(this)
  216. }, handler));
  217. }
  218. }
  219. exports.default = ReplaceSupers;