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