removal.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.remove = remove;
  6. exports._removeFromScope = _removeFromScope;
  7. exports._callRemovalHooks = _callRemovalHooks;
  8. exports._remove = _remove;
  9. exports._markRemoved = _markRemoved;
  10. exports._assertUnremoved = _assertUnremoved;
  11. var _removalHooks = require("./lib/removal-hooks");
  12. function remove() {
  13. this._assertUnremoved();
  14. this.resync();
  15. this._removeFromScope();
  16. if (this._callRemovalHooks()) {
  17. this._markRemoved();
  18. return;
  19. }
  20. this.shareCommentsWithSiblings();
  21. this._remove();
  22. this._markRemoved();
  23. }
  24. function _removeFromScope() {
  25. var _this = this;
  26. var bindings = this.getBindingIdentifiers();
  27. Object.keys(bindings).forEach(function (name) {
  28. return _this.scope.removeBinding(name);
  29. });
  30. }
  31. function _callRemovalHooks() {
  32. var _arr = _removalHooks.hooks;
  33. for (var _i = 0; _i < _arr.length; _i++) {
  34. var fn = _arr[_i];
  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. }