UNPKG

1.47 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.remove = remove;
7exports._removeFromScope = _removeFromScope;
8exports._callRemovalHooks = _callRemovalHooks;
9exports._remove = _remove;
10exports._markRemoved = _markRemoved;
11exports._assertUnremoved = _assertUnremoved;
12
13var _removalHooks = require("./lib/removal-hooks");
14
15var _index = require("./index");
16
17function 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
41function _removeFromScope() {
42 const bindings = this.getBindingIdentifiers();
43 Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
44}
45
46function _callRemovalHooks() {
47 for (const fn of _removalHooks.hooks) {
48 if (fn(this, this.parentPath)) return true;
49 }
50}
51
52function _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
61function _markRemoved() {
62 this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
63 this.node = null;
64}
65
66function _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