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.

block-hoist-plugin.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = loadBlockHoistPlugin;
  6. function _traverse() {
  7. const data = require("@babel/traverse");
  8. _traverse = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _plugin = require("../config/plugin");
  14. let LOADED_PLUGIN;
  15. function loadBlockHoistPlugin() {
  16. if (!LOADED_PLUGIN) {
  17. LOADED_PLUGIN = new _plugin.default(Object.assign({}, blockHoistPlugin, {
  18. visitor: _traverse().default.explode(blockHoistPlugin.visitor)
  19. }), {});
  20. }
  21. return LOADED_PLUGIN;
  22. }
  23. function priority(bodyNode) {
  24. const priority = bodyNode == null ? void 0 : bodyNode._blockHoist;
  25. if (priority == null) return 1;
  26. if (priority === true) return 2;
  27. return priority;
  28. }
  29. function stableSort(body) {
  30. const buckets = Object.create(null);
  31. for (let i = 0; i < body.length; i++) {
  32. const n = body[i];
  33. const p = priority(n);
  34. const bucket = buckets[p] || (buckets[p] = []);
  35. bucket.push(n);
  36. }
  37. const keys = Object.keys(buckets).map(k => +k).sort((a, b) => b - a);
  38. let index = 0;
  39. for (const key of keys) {
  40. const bucket = buckets[key];
  41. for (const n of bucket) {
  42. body[index++] = n;
  43. }
  44. }
  45. return body;
  46. }
  47. const blockHoistPlugin = {
  48. name: "internal.blockHoist",
  49. visitor: {
  50. Block: {
  51. exit({
  52. node
  53. }) {
  54. const {
  55. body
  56. } = node;
  57. let max = Math.pow(2, 30) - 1;
  58. let hasChange = false;
  59. for (let i = 0; i < body.length; i++) {
  60. const n = body[i];
  61. const p = priority(n);
  62. if (p > max) {
  63. hasChange = true;
  64. break;
  65. }
  66. max = p;
  67. }
  68. if (!hasChange) return;
  69. node.body = stableSort(body.slice());
  70. }
  71. }
  72. }
  73. };