You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

4 years ago
  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. var _index = require("./index");
  13. function remove() {
  14. this._assertUnremoved();
  15. this.resync();
  16. this._removeFromScope();
  17. if (this._callRemovalHooks()) {
  18. this._markRemoved();
  19. return;
  20. }
  21. this.shareCommentsWithSiblings();
  22. this._remove();
  23. this._markRemoved();
  24. }
  25. function _removeFromScope() {
  26. const bindings = this.getBindingIdentifiers();
  27. Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
  28. }
  29. function _callRemovalHooks() {
  30. for (const fn of _removalHooks.hooks) {
  31. if (fn(this, this.parentPath)) return true;
  32. }
  33. }
  34. function _remove() {
  35. if (Array.isArray(this.container)) {
  36. this.container.splice(this.key, 1);
  37. this.updateSiblingKeys(this.key, -1);
  38. } else {
  39. this._replaceWith(null);
  40. }
  41. }
  42. function _markRemoved() {
  43. this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
  44. this.node = null;
  45. }
  46. function _assertUnremoved() {
  47. if (this.removed) {
  48. throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
  49. }
  50. }