removal.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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");
  12. var _cache = require("../cache");
  13. var _index = require("./index");
  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) _cache.path.get(this.parent).delete(this.node);
  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. }
  56. //# sourceMappingURL=removal.js.map