removal.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. exports.__esModule = true;
  3. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  4. var _getIterator3 = _interopRequireDefault(_getIterator2);
  5. exports.remove = remove;
  6. exports._callRemovalHooks = _callRemovalHooks;
  7. exports._remove = _remove;
  8. exports._markRemoved = _markRemoved;
  9. exports._assertUnremoved = _assertUnremoved;
  10. var _removalHooks = require("./lib/removal-hooks");
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. function remove() {
  13. this._assertUnremoved();
  14. this.resync();
  15. if (this._callRemovalHooks()) {
  16. this._markRemoved();
  17. return;
  18. }
  19. this.shareCommentsWithSiblings();
  20. this._remove();
  21. this._markRemoved();
  22. }
  23. function _callRemovalHooks() {
  24. for (var _iterator = _removalHooks.hooks, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  25. var _ref;
  26. if (_isArray) {
  27. if (_i >= _iterator.length) break;
  28. _ref = _iterator[_i++];
  29. } else {
  30. _i = _iterator.next();
  31. if (_i.done) break;
  32. _ref = _i.value;
  33. }
  34. var fn = _ref;
  35. if (fn(this, this.parentPath)) return true;
  36. }
  37. }
  38. function _remove() {
  39. if (Array.isArray(this.container)) {
  40. this.container.splice(this.key, 1);
  41. this.updateSiblingKeys(this.key, -1);
  42. } else {
  43. this._replaceWith(null);
  44. }
  45. }
  46. function _markRemoved() {
  47. this.shouldSkip = true;
  48. this.removed = true;
  49. this.node = null;
  50. }
  51. function _assertUnremoved() {
  52. if (this.removed) {
  53. throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
  54. }
  55. }