removal.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports._assertUnremoved = _assertUnremoved;
  6. exports._callRemovalHooks = _callRemovalHooks;
  7. exports._markRemoved = _markRemoved;
  8. exports._remove = _remove;
  9. exports._removeFromScope = _removeFromScope;
  10. exports.remove = remove;
  11. var _removalHooks = require("./lib/removal-hooks.js");
  12. var _cache = require("../cache.js");
  13. var _index = require("./index.js");
  14. function remove() {
  15. var _this$opts;
  16. this._assertUnremoved();
  17. this.resync();
  18. if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
  19. this._removeFromScope();
  20. }
  21. if (this._callRemovalHooks()) {
  22. this._markRemoved();
  23. return;
  24. }
  25. this.shareCommentsWithSiblings();
  26. this._remove();
  27. this._markRemoved();
  28. }
  29. function _removeFromScope() {
  30. const bindings = this.getBindingIdentifiers();
  31. Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
  32. }
  33. function _callRemovalHooks() {
  34. for (const fn of _removalHooks.hooks) {
  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._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
  48. if (this.parent) {
  49. (0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node);
  50. }
  51. this.node = null;
  52. }
  53. function _assertUnremoved() {
  54. if (this.removed) {
  55. throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
  56. }
  57. }
  58. //# sourceMappingURL=removal.js.map