| 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 | var _modification = require("./modification.js");
|
|---|
| 18 | var _context = require("./context.js");
|
|---|
| 19 | function remove() {
|
|---|
| 20 | var _this$opts;
|
|---|
| 21 | _assertUnremoved.call(this);
|
|---|
| 22 | _context.resync.call(this);
|
|---|
| 23 | if (_callRemovalHooks.call(this)) {
|
|---|
| 24 | _markRemoved.call(this);
|
|---|
| 25 | return;
|
|---|
| 26 | }
|
|---|
| 27 | if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
|
|---|
| 28 | _removeFromScope.call(this);
|
|---|
| 29 | }
|
|---|
| 30 | this.shareCommentsWithSiblings();
|
|---|
| 31 | _remove.call(this);
|
|---|
| 32 | _markRemoved.call(this);
|
|---|
| 33 | }
|
|---|
| 34 | function _removeFromScope() {
|
|---|
| 35 | const bindings = t.getBindingIdentifiers(this.node, false, false, true);
|
|---|
| 36 | Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
|---|
| 37 | }
|
|---|
| 38 | function _callRemovalHooks() {
|
|---|
| 39 | if (this.parentPath) {
|
|---|
| 40 | for (const fn of _removalHooks.hooks) {
|
|---|
| 41 | if (fn(this, this.parentPath)) return true;
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | function _remove() {
|
|---|
| 46 | if (Array.isArray(this.container)) {
|
|---|
| 47 | this.container.splice(this.key, 1);
|
|---|
| 48 | _modification.updateSiblingKeys.call(this, this.key, -1);
|
|---|
| 49 | } else {
|
|---|
| 50 | _replacement._replaceWith.call(this, null);
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 | function _markRemoved() {
|
|---|
| 54 | this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
|
|---|
| 55 | if (this.parent) {
|
|---|
| 56 | var _getCachedPaths;
|
|---|
| 57 | (_getCachedPaths = (0, _cache.getCachedPaths)(this)) == null || _getCachedPaths.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
|
|---|