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