[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");
|
---|
| 17 | const {
|
---|
| 18 | getBindingIdentifiers
|
---|
| 19 | } = _t;
|
---|
| 20 | function remove() {
|
---|
| 21 | var _this$opts;
|
---|
| 22 | _assertUnremoved.call(this);
|
---|
| 23 | this.resync();
|
---|
| 24 | if (_callRemovalHooks.call(this)) {
|
---|
| 25 | _markRemoved.call(this);
|
---|
| 26 | return;
|
---|
| 27 | }
|
---|
| 28 | if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
|
---|
| 29 | _removeFromScope.call(this);
|
---|
| 30 | }
|
---|
| 31 | this.shareCommentsWithSiblings();
|
---|
| 32 | _remove.call(this);
|
---|
| 33 | _markRemoved.call(this);
|
---|
| 34 | }
|
---|
| 35 | function _removeFromScope() {
|
---|
| 36 | const bindings = getBindingIdentifiers(this.node, false, false, true);
|
---|
| 37 | Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
---|
| 38 | }
|
---|
| 39 | function _callRemovalHooks() {
|
---|
| 40 | if (this.parentPath) {
|
---|
| 41 | for (const fn of _removalHooks.hooks) {
|
---|
| 42 | if (fn(this, this.parentPath)) return true;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | function _remove() {
|
---|
| 47 | if (Array.isArray(this.container)) {
|
---|
| 48 | this.container.splice(this.key, 1);
|
---|
| 49 | this.updateSiblingKeys(this.key, -1);
|
---|
| 50 | } else {
|
---|
| 51 | _replacement._replaceWith.call(this, null);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | function _markRemoved() {
|
---|
| 55 | this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
|
---|
| 56 | if (this.parent) {
|
---|
| 57 | (0, _cache.getCachedPaths)(this.hub, this.parent).delete(this.node);
|
---|
| 58 | }
|
---|
| 59 | this.node = null;
|
---|
| 60 | }
|
---|
| 61 | function _assertUnremoved() {
|
---|
| 62 | if (this.removed) {
|
---|
| 63 | throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | //# sourceMappingURL=removal.js.map
|
---|