[d565449] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports._assertUnremoved = _assertUnremoved;
|
---|
| 7 | exports._callRemovalHooks = _callRemovalHooks;
|
---|
| 8 | exports._markRemoved = _markRemoved;
|
---|
| 9 | exports._remove = _remove;
|
---|
| 10 | exports._removeFromScope = _removeFromScope;
|
---|
| 11 | exports.remove = remove;
|
---|
| 12 | var _removalHooks = require("./lib/removal-hooks.js");
|
---|
| 13 | var _cache = require("../cache.js");
|
---|
| 14 | var _replacement = require("./replacement.js");
|
---|
| 15 | var _index = require("./index.js");
|
---|
| 16 | var _t = require("@babel/types");
|
---|
[0c6b92a] | 17 | var _modification = require("./modification.js");
|
---|
| 18 | var _context = require("./context.js");
|
---|
[d565449] | 19 | const {
|
---|
| 20 | getBindingIdentifiers
|
---|
| 21 | } = _t;
|
---|
| 22 | function remove() {
|
---|
| 23 | var _this$opts;
|
---|
| 24 | _assertUnremoved.call(this);
|
---|
[0c6b92a] | 25 | _context.resync.call(this);
|
---|
[d565449] | 26 | if (_callRemovalHooks.call(this)) {
|
---|
| 27 | _markRemoved.call(this);
|
---|
| 28 | return;
|
---|
| 29 | }
|
---|
| 30 | if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
|
---|
| 31 | _removeFromScope.call(this);
|
---|
| 32 | }
|
---|
| 33 | this.shareCommentsWithSiblings();
|
---|
| 34 | _remove.call(this);
|
---|
| 35 | _markRemoved.call(this);
|
---|
| 36 | }
|
---|
| 37 | function _removeFromScope() {
|
---|
| 38 | const bindings = getBindingIdentifiers(this.node, false, false, true);
|
---|
| 39 | Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
---|
| 40 | }
|
---|
| 41 | function _callRemovalHooks() {
|
---|
| 42 | if (this.parentPath) {
|
---|
| 43 | for (const fn of _removalHooks.hooks) {
|
---|
| 44 | if (fn(this, this.parentPath)) return true;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | function _remove() {
|
---|
| 49 | if (Array.isArray(this.container)) {
|
---|
| 50 | this.container.splice(this.key, 1);
|
---|
[0c6b92a] | 51 | _modification.updateSiblingKeys.call(this, this.key, -1);
|
---|
[d565449] | 52 | } else {
|
---|
| 53 | _replacement._replaceWith.call(this, null);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | function _markRemoved() {
|
---|
| 57 | this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
|
---|
| 58 | if (this.parent) {
|
---|
| 59 | (0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node);
|
---|
| 60 | }
|
---|
| 61 | this.node = null;
|
---|
| 62 | }
|
---|
| 63 | function _assertUnremoved() {
|
---|
| 64 | if (this.removed) {
|
---|
| 65 | throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | //# sourceMappingURL=removal.js.map
|
---|