Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

58 rindas
1.3 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _NodePath = _interopRequireDefault(require("./NodePath"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. class TraversalContext {
  9. constructor({
  10. state,
  11. opts
  12. }) {
  13. this.state = state;
  14. this.opts = opts;
  15. }
  16. visit(node, key) {
  17. const nodes = node[key];
  18. if (!nodes) return false;
  19. if (typeof nodes.length === 'number') return this.visitMultiple(nodes, node, key);
  20. return this.visitSingle(node, key);
  21. }
  22. visitMultiple(container, parent, listKey) {
  23. if (container.length === 0) return false;
  24. let shouldStop = false;
  25. Array.from(container).forEach((value, key) => {
  26. if (shouldStop) return;
  27. const nodePath = this.create(parent, container, key, listKey);
  28. if (nodePath && nodePath.visit()) shouldStop = true;
  29. });
  30. return shouldStop;
  31. }
  32. visitSingle(node, key) {
  33. const nodePath = this.create(node, node, key);
  34. if (!nodePath) return false;
  35. return nodePath.visit();
  36. }
  37. create(parent, container, key, listKey) {
  38. return _NodePath.default.get({
  39. parent,
  40. container,
  41. key,
  42. listKey,
  43. context: this
  44. });
  45. }
  46. }
  47. var _default = TraversalContext;
  48. exports.default = _default;