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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _default;
  6. var _helperGetFunctionArity = require("@babel/helper-get-function-arity");
  7. var _template = require("@babel/template");
  8. var t = require("@babel/types");
  9. const buildPropertyMethodAssignmentWrapper = (0, _template.default)(`
  10. (function (FUNCTION_KEY) {
  11. function FUNCTION_ID() {
  12. return FUNCTION_KEY.apply(this, arguments);
  13. }
  14. FUNCTION_ID.toString = function () {
  15. return FUNCTION_KEY.toString();
  16. }
  17. return FUNCTION_ID;
  18. })(FUNCTION)
  19. `);
  20. const buildGeneratorPropertyMethodAssignmentWrapper = (0, _template.default)(`
  21. (function (FUNCTION_KEY) {
  22. function* FUNCTION_ID() {
  23. return yield* FUNCTION_KEY.apply(this, arguments);
  24. }
  25. FUNCTION_ID.toString = function () {
  26. return FUNCTION_KEY.toString();
  27. };
  28. return FUNCTION_ID;
  29. })(FUNCTION)
  30. `);
  31. const visitor = {
  32. "ReferencedIdentifier|BindingIdentifier"(path, state) {
  33. if (path.node.name !== state.name) return;
  34. const localDeclar = path.scope.getBindingIdentifier(state.name);
  35. if (localDeclar !== state.outerDeclar) return;
  36. state.selfReference = true;
  37. path.stop();
  38. }
  39. };
  40. function getNameFromLiteralId(id) {
  41. if (t.isNullLiteral(id)) {
  42. return "null";
  43. }
  44. if (t.isRegExpLiteral(id)) {
  45. return `_${id.pattern}_${id.flags}`;
  46. }
  47. if (t.isTemplateLiteral(id)) {
  48. return id.quasis.map(quasi => quasi.value.raw).join("");
  49. }
  50. if (id.value !== undefined) {
  51. return id.value + "";
  52. }
  53. return "";
  54. }
  55. function wrap(state, method, id, scope) {
  56. if (state.selfReference) {
  57. if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
  58. scope.rename(id.name);
  59. } else {
  60. if (!t.isFunction(method)) return;
  61. let build = buildPropertyMethodAssignmentWrapper;
  62. if (method.generator) {
  63. build = buildGeneratorPropertyMethodAssignmentWrapper;
  64. }
  65. const template = build({
  66. FUNCTION: method,
  67. FUNCTION_ID: id,
  68. FUNCTION_KEY: scope.generateUidIdentifier(id.name)
  69. }).expression;
  70. const params = template.callee.body.body[0].params;
  71. for (let i = 0, len = (0, _helperGetFunctionArity.default)(method); i < len; i++) {
  72. params.push(scope.generateUidIdentifier("x"));
  73. }
  74. return template;
  75. }
  76. }
  77. method.id = id;
  78. scope.getProgramParent().references[id.name] = true;
  79. }
  80. function visit(node, name, scope) {
  81. const state = {
  82. selfAssignment: false,
  83. selfReference: false,
  84. outerDeclar: scope.getBindingIdentifier(name),
  85. references: [],
  86. name: name
  87. };
  88. const binding = scope.getOwnBinding(name);
  89. if (binding) {
  90. if (binding.kind === "param") {
  91. state.selfReference = true;
  92. } else {}
  93. } else if (state.outerDeclar || scope.hasGlobal(name)) {
  94. scope.traverse(node, visitor, state);
  95. }
  96. return state;
  97. }
  98. function _default({
  99. node,
  100. parent,
  101. scope,
  102. id
  103. }, localBinding = false) {
  104. if (node.id) return;
  105. if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, {
  106. kind: "method"
  107. })) && (!parent.computed || t.isLiteral(parent.key))) {
  108. id = parent.key;
  109. } else if (t.isVariableDeclarator(parent)) {
  110. id = parent.id;
  111. if (t.isIdentifier(id) && !localBinding) {
  112. const binding = scope.parent.getBinding(id.name);
  113. if (binding && binding.constant && scope.getBinding(id.name) === binding) {
  114. node.id = t.cloneNode(id);
  115. node.id[t.NOT_LOCAL_BINDING] = true;
  116. return;
  117. }
  118. }
  119. } else if (t.isAssignmentExpression(parent, {
  120. operator: "="
  121. })) {
  122. id = parent.left;
  123. } else if (!id) {
  124. return;
  125. }
  126. let name;
  127. if (id && t.isLiteral(id)) {
  128. name = getNameFromLiteralId(id);
  129. } else if (id && t.isIdentifier(id)) {
  130. name = id.name;
  131. }
  132. if (name === undefined) {
  133. return;
  134. }
  135. name = t.toBindingIdentifierName(name);
  136. id = t.identifier(name);
  137. id[t.NOT_LOCAL_BINDING] = true;
  138. const state = visit(node, name, scope);
  139. return wrap(state, node, id, scope) || node;
  140. }