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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.needsWhitespace = needsWhitespace;
  6. exports.needsWhitespaceBefore = needsWhitespaceBefore;
  7. exports.needsWhitespaceAfter = needsWhitespaceAfter;
  8. exports.needsParens = needsParens;
  9. var whitespace = require("./whitespace");
  10. var parens = require("./parentheses");
  11. var t = require("@babel/types");
  12. function expandAliases(obj) {
  13. const newObj = {};
  14. function add(type, func) {
  15. const fn = newObj[type];
  16. newObj[type] = fn ? function (node, parent, stack) {
  17. const result = fn(node, parent, stack);
  18. return result == null ? func(node, parent, stack) : result;
  19. } : func;
  20. }
  21. for (const type of Object.keys(obj)) {
  22. const aliases = t.FLIPPED_ALIAS_KEYS[type];
  23. if (aliases) {
  24. for (const alias of aliases) {
  25. add(alias, obj[type]);
  26. }
  27. } else {
  28. add(type, obj[type]);
  29. }
  30. }
  31. return newObj;
  32. }
  33. const expandedParens = expandAliases(parens);
  34. const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
  35. const expandedWhitespaceList = expandAliases(whitespace.list);
  36. function find(obj, node, parent, printStack) {
  37. const fn = obj[node.type];
  38. return fn ? fn(node, parent, printStack) : null;
  39. }
  40. function isOrHasCallExpression(node) {
  41. if (t.isCallExpression(node)) {
  42. return true;
  43. }
  44. return t.isMemberExpression(node) && isOrHasCallExpression(node.object);
  45. }
  46. function needsWhitespace(node, parent, type) {
  47. if (!node) return 0;
  48. if (t.isExpressionStatement(node)) {
  49. node = node.expression;
  50. }
  51. let linesInfo = find(expandedWhitespaceNodes, node, parent);
  52. if (!linesInfo) {
  53. const items = find(expandedWhitespaceList, node, parent);
  54. if (items) {
  55. for (let i = 0; i < items.length; i++) {
  56. linesInfo = needsWhitespace(items[i], node, type);
  57. if (linesInfo) break;
  58. }
  59. }
  60. }
  61. if (typeof linesInfo === "object" && linesInfo !== null) {
  62. return linesInfo[type] || 0;
  63. }
  64. return 0;
  65. }
  66. function needsWhitespaceBefore(node, parent) {
  67. return needsWhitespace(node, parent, "before");
  68. }
  69. function needsWhitespaceAfter(node, parent) {
  70. return needsWhitespace(node, parent, "after");
  71. }
  72. function needsParens(node, parent, printStack) {
  73. if (!parent) return false;
  74. if (t.isNewExpression(parent) && parent.callee === node) {
  75. if (isOrHasCallExpression(node)) return true;
  76. }
  77. return find(expandedParens, node, parent, printStack);
  78. }