Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

144 Zeilen
3.1 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _h2xTypes = require("h2x-types");
  7. var _ = _interopRequireDefault(require("."));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /* eslint-disable no-restricted-syntax, no-continue, no-underscore-dangle */
  10. class NodePath {
  11. static get({
  12. parent,
  13. container,
  14. listKey,
  15. key,
  16. context
  17. }) {
  18. const node = container[key];
  19. if (!node) return null;
  20. return new NodePath({
  21. listKey,
  22. key,
  23. parent,
  24. container,
  25. node,
  26. context
  27. });
  28. }
  29. constructor({
  30. container,
  31. parent,
  32. key,
  33. listKey,
  34. node,
  35. context
  36. }) {
  37. this.container = container;
  38. this.parent = parent;
  39. this.listKey = listKey;
  40. this.key = key;
  41. this.node = node;
  42. this.context = context;
  43. this.state = context.state;
  44. this.opts = context.opts;
  45. this.type = (0, _h2xTypes.getNodeType)(node);
  46. this.shouldStop = false;
  47. }
  48. visit() {
  49. if (this.call('enter')) this.shouldStop = true;
  50. (0, _.default)(this.node, this.opts, this.state);
  51. if (this.call('exit')) this.shouldStop = true;
  52. return this.shouldStop;
  53. }
  54. call(key) {
  55. const opts = this.opts;
  56. if (this.node) {
  57. if (this._call(opts[key])) return true;
  58. return this._call(opts[this.type] && opts[this.type][key]);
  59. }
  60. return false;
  61. }
  62. resyncKey() {
  63. if (!this.container) return;
  64. for (let i = 0; i < this.container.length; i += 1) {
  65. if (this.container[i] === this.node) this.key = i;
  66. }
  67. }
  68. replace(node) {
  69. this.shouldStop = true;
  70. this.node = node;
  71. this.container[this.key] = node;
  72. this.requeue();
  73. }
  74. remove() {
  75. this.shouldStop = true;
  76. if (Array.isArray(this.container)) {
  77. this.container.splice(this.key, 1);
  78. } else {
  79. this.container[this.key] = null;
  80. }
  81. this.node = null;
  82. this.requeue();
  83. }
  84. requeue() {
  85. this.context.visit(this.parent, this.listKey);
  86. }
  87. _call(fns) {
  88. if (!fns) return false;
  89. if (!Array.isArray(fns)) fns = [fns];
  90. var _iteratorNormalCompletion = true;
  91. var _didIteratorError = false;
  92. var _iteratorError = undefined;
  93. try {
  94. for (var _iterator = fns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  95. const fn = _step.value;
  96. if (!fn) continue;
  97. const node = this.node;
  98. if (!node) return true;
  99. const ret = fn(this, this.state);
  100. if (ret) throw new Error(`Unexpected return value from visitor method ${fn}`); // node has been replaced, it will have been requeued
  101. if (this.node !== node) return true;
  102. }
  103. } catch (err) {
  104. _didIteratorError = true;
  105. _iteratorError = err;
  106. } finally {
  107. try {
  108. if (!_iteratorNormalCompletion && _iterator.return != null) {
  109. _iterator.return();
  110. }
  111. } finally {
  112. if (_didIteratorError) {
  113. throw _iteratorError;
  114. }
  115. }
  116. }
  117. return false;
  118. }
  119. }
  120. var _default = NodePath;
  121. exports.default = _default;