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.

traverse.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = traverse;
  6. var _definitions = require("../definitions");
  7. function traverse(node, handlers, state) {
  8. if (typeof handlers === "function") {
  9. handlers = {
  10. enter: handlers
  11. };
  12. }
  13. const {
  14. enter,
  15. exit
  16. } = handlers;
  17. traverseSimpleImpl(node, enter, exit, state, []);
  18. }
  19. function traverseSimpleImpl(node, enter, exit, state, ancestors) {
  20. const keys = _definitions.VISITOR_KEYS[node.type];
  21. if (!keys) return;
  22. if (enter) enter(node, ancestors, state);
  23. for (const key of keys) {
  24. const subNode = node[key];
  25. if (Array.isArray(subNode)) {
  26. for (let i = 0; i < subNode.length; i++) {
  27. const child = subNode[i];
  28. if (!child) continue;
  29. ancestors.push({
  30. node,
  31. key,
  32. index: i
  33. });
  34. traverseSimpleImpl(child, enter, exit, state, ancestors);
  35. ancestors.pop();
  36. }
  37. } else if (subNode) {
  38. ancestors.push({
  39. node,
  40. key
  41. });
  42. traverseSimpleImpl(subNode, enter, exit, state, ancestors);
  43. ancestors.pop();
  44. }
  45. }
  46. if (exit) exit(node, ancestors, state);
  47. }