| 1 | // This file contains methods responsible for removing a node. |
| 2 | |
| 3 | import { hooksscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`removal-hooks.ts`/hooks. } from "./lib/removal-hooks"scip-typescript npm @babel/traverse 7.20.13 src/path/lib/`removal-hooks.ts`/; |
| 4 | import { pathscip-typescript npm @babel/traverse 7.20.13 src/`cache.ts`/path. as pathCachescip-typescript npm @babel/traverse 7.20.13 src/`cache.ts`/path. } from "../cache"scip-typescript npm @babel/traverse 7.20.13 src/`cache.ts`/; |
| 5 | import type NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# from "./index"scip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/; |
| 6 | import { REMOVEDscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/REMOVED., SHOULD_SKIPscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/SHOULD_SKIP. } from "./index"scip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/; |
| 7 | |
| 8 | export function removescip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/remove().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/remove().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 9 | this._assertUnremovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(); |
| 10 | |
| 11 | this.resyncscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/resync().(); |
| 12 | if (!this.optsscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#opts.?.noScope) { |
| 13 | this._removeFromScopescip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_removeFromScope().(); |
| 14 | } |
| 15 | |
| 16 | if (this._callRemovalHooksscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_callRemovalHooks().()) { |
| 17 | this._markRemovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_markRemoved().(); |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | this.shareCommentsWithSiblingsscip-typescript npm @babel/traverse 7.20.13 src/path/`comments.ts`/shareCommentsWithSiblings().(); |
| 22 | this._removescip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_remove().(); |
| 23 | this._markRemovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_markRemoved().(); |
| 24 | } |
| 25 | |
| 26 | export function _removeFromScopescip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_removeFromScope().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_removeFromScope().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 27 | const bindings = this.getBindingIdentifiers(); |
| 28 | Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(bindings).forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(name => this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..removeBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#removeBinding().(name)); |
| 29 | } |
| 30 | |
| 31 | export function _callRemovalHooksscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_callRemovalHooks().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_callRemovalHooks().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 32 | for (const fn of hooksscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`removal-hooks.ts`/hooks.) { |
| 33 | if (fn(this, this.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.)) return true; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | export function _removescip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_remove().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_remove().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 38 | if (Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.isArrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ArrayConstructor#isArray().(this.containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container.)) { |
| 39 | this.containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container..splicescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#splice().(this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. as number, 1); |
| 40 | this.updateSiblingKeysscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. as number, -1); |
| 41 | } else { |
| 42 | this._replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/_replaceWith().(null); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | export function _markRemovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_markRemoved().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_markRemoved().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 47 | // this.shouldSkip = true; this.removed = true; |
| 48 | this._traverseFlagsscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#_traverseFlags. |= SHOULD_SKIPscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/SHOULD_SKIP. | REMOVEDscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/REMOVED.; |
| 49 | if (this.parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent.) pathCachescip-typescript npm @babel/traverse 7.20.13 src/`cache.ts`/path..getscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/WeakMap#get().(this.parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent.).delete(this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 50 | this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. = null; |
| 51 | } |
| 52 | |
| 53 | export function _assertUnremovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(thisscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 54 | if (this.removedscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#`<get>removed`().) { |
| 55 | throw this.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 56 | "NodePath has been removed so is read-only.", |
| 57 | ); |
| 58 | } |
| 59 | } |