| 1 | // This file contains methods that modify the path/node in some ways. |
| 2 | |
| 3 | 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`/; |
| 4 | import PathHoisterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister# from "./lib/hoister"scip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/; |
| 5 | import 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 { |
| 7 | arrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/arrowFunctionExpression()., |
| 8 | assertExpressionscip-typescript npm @babel/types 7.20.7 src/asserts/generated/`index.ts`/assertExpression()., |
| 9 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression()., |
| 10 | blockStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/blockStatement()., |
| 11 | callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression()., |
| 12 | cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode()., |
| 13 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement()., |
| 14 | isAssignmentExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isAssignmentExpression()., |
| 15 | isCallExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isCallExpression()., |
| 16 | isExportNamedDeclarationscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExportNamedDeclaration()., |
| 17 | isExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExpression()., |
| 18 | isIdentifierscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isIdentifier()., |
| 19 | isSequenceExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isSequenceExpression()., |
| 20 | isSuperscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isSuper()., |
| 21 | thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression()., |
| 22 | } from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 23 | import type * as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 24 | import type Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope# from "../scope"scip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/; |
| 25 | |
| 26 | /** |
| 27 | * Insert the provided nodes before the current one. |
| 28 | */ |
| 29 | |
| 30 | export function insertBeforescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertBefore().( |
| 31 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertBefore().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 32 | nodes_scip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertBefore().(nodes_): tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#[], |
| 33 | ): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[] { |
| 34 | this._assertUnremovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(); |
| 35 | |
| 36 | const nodes = this._verifyNodeListscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes_scip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertBefore().(nodes_)); |
| 37 | |
| 38 | const { parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath., parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent. } = this; |
| 39 | |
| 40 | if ( |
| 41 | parentPath.isExpressionStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExpressionStatement().() || |
| 42 | parentPath.isLabeledStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLabeledStatement().() || |
| 43 | // https://github.com/babel/babel/issues/15293 |
| 44 | // When Babel transforms `export class String { field }`, the class properties plugin will inject the defineProperty |
| 45 | // helper, which depends on the builtins e.g. String, Number, Symbol, etc. To prevent them from being shadowed by local |
| 46 | // exports, the helper injector replaces the named export into `class _String { field }; export { _String as String }`, |
| 47 | // with `parentPath` here changed to the moved ClassDeclaration, causing rare inconsistency between `parent` and `parentPath`. |
| 48 | // Here we retrieve the parent type from the `parent` property. This is a temporary fix and we should revisit when |
| 49 | // helpers should get injected. |
| 50 | isExportNamedDeclarationscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExportNamedDeclaration().(parent) || |
| 51 | (parentPath.isExportDefaultDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportDefaultDeclaration().() && this.isDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isDeclaration().()) |
| 52 | ) { |
| 53 | return parentPath.insertBeforescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertBefore().(nodes); |
| 54 | } else if ( |
| 55 | (this.isNodeTypescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isNodeType().("Expression") && !this.isJSXElementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXElement().()) || |
| 56 | (parentPath.isForStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isForStatement().() && this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. === "init") |
| 57 | ) { |
| 58 | if (this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.) nodes.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 59 | // @ts-expect-error todo(flow->ts): check that nodes is an array of statements |
| 60 | return this.replaceExpressionWithStatementsscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceExpressionWithStatements().(nodes); |
| 61 | } else 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.)) { |
| 62 | return this._containerInsertBeforescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().(nodes); |
| 63 | } else if (this.isStatementOrBlockscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isStatementOrBlock().()) { |
| 64 | const node = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Statementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Statement#; |
| 65 | const shouldInsertCurrentNode = |
| 66 | node && |
| 67 | (!this.isExpressionStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExpressionStatement().() || |
| 68 | (node as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ExpressionStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExpressionStatement#).expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExpressionStatement#expression. != null); |
| 69 | |
| 70 | this.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(blockStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/blockStatement().(shouldInsertCurrentNode ? [node] : [])); |
| 71 | return (this as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.BlockStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/BlockStatement#>).unshiftContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().( |
| 72 | "body", |
| 73 | // @ts-expect-error Fixme: refine nodes to t.BlockStatement["body"] when this is a BlockStatement path |
| 74 | nodes, |
| 75 | ); |
| 76 | } else { |
| 77 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#( |
| 78 | "We don't know what to do with this node type. " + |
| 79 | "We were previously a Statement but we can't fit in here?", |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | export function _containerInsertscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#>( |
| 85 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 86 | fromscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(from): number, |
| 87 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(nodes): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().[N][], |
| 88 | ): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().[N]>[] { |
| 89 | this.updateSiblingKeysscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(fromscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(from), nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(nodes).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.); |
| 90 | |
| 91 | const paths: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().[N]>[] = []; |
| 92 | |
| 93 | // @ts-expect-error todo(flow->ts): this.container could be a NodePath |
| 94 | this.containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container..splice(fromscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(from), 0, ...nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(nodes)); |
| 95 | for (let i = 0; i < nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(nodes).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.; i++) { |
| 96 | const to = fromscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(from) + i; |
| 97 | const path = this.getSiblingscip-typescript npm @babel/traverse 7.20.13 src/path/`family.ts`/getSibling().(to) as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().[N]>; |
| 98 | paths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(path); |
| 99 | |
| 100 | if (this.contextscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#context. && this.contextscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#context..queuescip-typescript npm @babel/traverse 7.20.13 src/`context.ts`/TraversalContext#queue.) { |
| 101 | path.pushContextscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/pushContext().(this.contextscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#context.); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | const contexts = this._getQueueContextsscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/_getQueueContexts().(); |
| 106 | |
| 107 | for (const path of paths) { |
| 108 | path.setScopescip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/setScope().(); |
| 109 | path.debugscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#debug().("Inserted."); |
| 110 | |
| 111 | for (const context of contexts) { |
| 112 | context.maybeQueuescip-typescript npm @babel/traverse 7.20.13 src/`context.ts`/TraversalContext#maybeQueue().(path, true); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return paths; |
| 117 | } |
| 118 | |
| 119 | export function _containerInsertBeforescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#>( |
| 120 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 121 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().(nodes): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().[N][], |
| 122 | ) { |
| 123 | return this._containerInsertscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().(this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. as number, nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().(nodes)); |
| 124 | } |
| 125 | |
| 126 | export function _containerInsertAfterscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#>( |
| 127 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 128 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().(nodes): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().[N][], |
| 129 | ) { |
| 130 | return this._containerInsertscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsert().((this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. as number) + 1, nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().(nodes)); |
| 131 | } |
| 132 | |
| 133 | const lastscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/last. = <T>(arr: T[]) => arr[arr.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. - 1]; |
| 134 | |
| 135 | function isHiddenInSequenceExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#): boolean { |
| 136 | return ( |
| 137 | isSequenceExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isSequenceExpression().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(path).parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent.) && |
| 138 | (lastscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/last.(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(path).parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent..expressionsscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/SequenceExpression#expressions.) !== pathscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(path).nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. || |
| 139 | isHiddenInSequenceExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.)) |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | function isAlmostConstantAssignmentscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().( |
| 144 | nodescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node): tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#, |
| 145 | scopescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(scope): Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#, |
| 146 | ): nodescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node) is tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.AssignmentExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression# & { left: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier# } { |
| 147 | if (!isAssignmentExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isAssignmentExpression().(nodescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node)) || !isIdentifierscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isIdentifier().(nodescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node).leftscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#left.)) { |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | // Not every scope can contain variables. For example, we might be in |
| 152 | // a ClassScope either in the ClassHeritage or in a computed key. |
| 153 | const blockScope = scopescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(scope).getBlockParentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBlockParent().(); |
| 154 | |
| 155 | // If the variable is defined in the current scope and only assigned here, |
| 156 | // we can be sure that its value won't change. |
| 157 | return ( |
| 158 | blockScope.hasOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#hasOwnBinding().(nodescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node).leftscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#left..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.) && |
| 159 | blockScope.getOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getOwnBinding().(nodescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node).leftscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#left..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.).constantViolationsscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constantViolations..lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. <= 1 |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Insert the provided nodes after the current one. When inserting nodes after an |
| 165 | * expression, ensure that the completion record is correct by pushing the current node. |
| 166 | */ |
| 167 | |
| 168 | export function insertAfterscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().( |
| 169 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 170 | nodes_scip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().(nodes_): tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#[], |
| 171 | ): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[] { |
| 172 | this._assertUnremovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(); |
| 173 | |
| 174 | if (this.isSequenceExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isSequenceExpression().()) { |
| 175 | return lastscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/last.(this.get("expressions")).insertAfterscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().(nodes_scip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().(nodes_)); |
| 176 | } |
| 177 | |
| 178 | const nodes = this._verifyNodeListscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes_scip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().(nodes_)); |
| 179 | |
| 180 | const { parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath., parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent. } = this; |
| 181 | if ( |
| 182 | parentPath.isExpressionStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExpressionStatement().() || |
| 183 | parentPath.isLabeledStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isLabeledStatement().() || |
| 184 | // see insertBefore |
| 185 | isExportNamedDeclarationscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExportNamedDeclaration().(parent) || |
| 186 | (parentPath.isExportDefaultDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportDefaultDeclaration().() && this.isDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isDeclaration().()) |
| 187 | ) { |
| 188 | return parentPath.insertAfterscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().( |
| 189 | nodes.mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(node => { |
| 190 | // Usually after an expression we can safely insert another expression: |
| 191 | // A.insertAfter(B) |
| 192 | // foo = A; -> foo = (A, B); |
| 193 | // If A is an expression statement, it isn't safe anymore so we need to |
| 194 | // convert B to an expression statement |
| 195 | // A; -> A; B // No semicolon! It could break if followed by [! |
| 196 | return isExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExpression().(node) ? expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().(node) : node; |
| 197 | }), |
| 198 | ); |
| 199 | } else if ( |
| 200 | (this.isNodeTypescip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isNodeType().("Expression") && |
| 201 | !this.isJSXElementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXElement().() && |
| 202 | !parentPath.isJSXElementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXElement().()) || |
| 203 | (parentPath.isForStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isForStatement().() && this.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. === "init") |
| 204 | ) { |
| 205 | if (this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.) { |
| 206 | const node = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.VariableDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclaration#; |
| 207 | let { scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope. } = this; |
| 208 | |
| 209 | if (scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isPatternscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isPattern().()) { |
| 210 | assertExpressionscip-typescript npm @babel/types 7.20.7 src/asserts/generated/`index.ts`/assertExpression().(node); |
| 211 | |
| 212 | this.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(callExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/callExpression().(arrowFunctionExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/arrowFunctionExpression().([], node), [])); |
| 213 | (this.get("callee.body") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#>).insertAfterscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/insertAfter().(nodes); |
| 214 | return [this]; |
| 215 | } |
| 216 | |
| 217 | if (isHiddenInSequenceExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isHiddenInSequenceExpression().(this)) { |
| 218 | nodes.unshiftscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#unshift().(node); |
| 219 | } |
| 220 | // We need to preserve the value of this expression. |
| 221 | else if (isCallExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isCallExpression().(node) && isSuperscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isSuper().(node.calleescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#callee.)) { |
| 222 | nodes.unshiftscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#unshift().(node); |
| 223 | // `super(...)` always evaluates to `this`. |
| 224 | nodes.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(thisExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/thisExpression().()); |
| 225 | } else if (isAlmostConstantAssignmentscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/isAlmostConstantAssignment().(node, scope)) { |
| 226 | nodes.unshiftscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#unshift().(node); |
| 227 | nodes.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode().(node.leftscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/AssignmentExpression#left.)); |
| 228 | } else if (scope.isPurescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#isPure().(node, true)) { |
| 229 | // Insert the nodes before rather than after; it's not observable. |
| 230 | nodes.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(node); |
| 231 | } else { |
| 232 | // Inserting after the computed key of a method should insert the |
| 233 | // temporary binding in the method's parent's scope. |
| 234 | if (parentPath.isMethodscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isMethod().({ computedscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/computed0:: true, keyscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/key0:: node })) { |
| 235 | scope = scope.parentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#`<get>parent`().; |
| 236 | } |
| 237 | const temp = scope.generateDeclaredUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateDeclaredUidIdentifier().(); |
| 238 | nodes.unshiftscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#unshift().( |
| 239 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().( |
| 240 | // @ts-expect-error todo(flow->ts): This can be a variable |
| 241 | // declaraion in the "init" of a for statement, but that's |
| 242 | // invalid here. |
| 243 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode().(temp), node), |
| 244 | ), |
| 245 | ); |
| 246 | nodes.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().(cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode().(temp))); |
| 247 | } |
| 248 | } |
| 249 | // @ts-expect-error todo(flow->ts): check that nodes is an array of statements |
| 250 | return this.replaceExpressionWithStatementsscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceExpressionWithStatements().(nodes); |
| 251 | } else 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.)) { |
| 252 | return this._containerInsertAfterscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertAfter().(nodes); |
| 253 | } else if (this.isStatementOrBlockscip-typescript npm @babel/traverse 7.20.13 src/path/`introspection.ts`/isStatementOrBlock().()) { |
| 254 | const node = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Statementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Statement#; |
| 255 | const shouldInsertCurrentNode = |
| 256 | node && |
| 257 | (!this.isExpressionStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExpressionStatement().() || |
| 258 | (node as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ExpressionStatementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExpressionStatement#).expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExpressionStatement#expression. != null); |
| 259 | |
| 260 | this.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(blockStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/blockStatement().(shouldInsertCurrentNode ? [node] : [])); |
| 261 | // @ts-expect-error Fixme: refine nodes to t.BlockStatement["body"] when this is a BlockStatement path |
| 262 | return this.pushContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().("body", nodes); |
| 263 | } else { |
| 264 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#( |
| 265 | "We don't know what to do with this node type. " + |
| 266 | "We were previously a Statement but we can't fit in here?", |
| 267 | ); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Update all sibling node paths after `fromIndex` by `incrementBy`. |
| 273 | */ |
| 274 | |
| 275 | export function updateSiblingKeysscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().( |
| 276 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 277 | fromIndexscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(fromIndex): number, |
| 278 | incrementByscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(incrementBy): number, |
| 279 | ) { |
| 280 | if (!this.parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent.) return; |
| 281 | |
| 282 | const paths = 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.); |
| 283 | for (const [, path] of paths) { |
| 284 | if (path.key >= fromIndexscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(fromIndex)) { |
| 285 | path.key += incrementByscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/updateSiblingKeys().(incrementBy); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | export function _verifyNodeListscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#>( |
| 291 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 292 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().[N] | Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().[N][], |
| 293 | ): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().[N][] { |
| 294 | if (!nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes)) { |
| 295 | return []; |
| 296 | } |
| 297 | |
| 298 | 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().(nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes))) { |
| 299 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes) = [nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes)]; |
| 300 | } |
| 301 | |
| 302 | for (let i = 0; i < nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.; i++) { |
| 303 | const node = nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes)[i]; |
| 304 | let msg; |
| 305 | |
| 306 | if (!node) { |
| 307 | msg = "has falsy node"; |
| 308 | } else if (typeof node !== "object") { |
| 309 | msg = "contains a non-object node"; |
| 310 | } else if (!node.typescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ArrayExpression#type.) { |
| 311 | msg = "without a type"; |
| 312 | } else if (node instanceof NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 313 | msg = "has a NodePath when it expected a raw object"; |
| 314 | } |
| 315 | |
| 316 | if (msg) { |
| 317 | const type = 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().(node) ? "array" : typeof node; |
| 318 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#( |
| 319 | `Node list ${msg} with the index of ${i} and type of ${type}`, |
| 320 | ); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | return nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodes); |
| 325 | } |
| 326 | |
| 327 | export function unshiftContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#, Kscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[K] extends keyof Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[N] & string>( |
| 328 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[N]>, |
| 329 | listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(listKey): Kscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[K], |
| 330 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(nodes): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[N][Kscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().[K]] extends (infer E)[] |
| 331 | ? E | E[] |
| 332 | : // todo: refine to t.Node[] |
| 333 | // ? E extends t.Node |
| 334 | // ? E | E[] |
| 335 | // : never |
| 336 | never, |
| 337 | ) { |
| 338 | // todo: NodePaths<Nodes> |
| 339 | this._assertUnremovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(); |
| 340 | |
| 341 | // @ts-expect-error fixme |
| 342 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(nodes) = this._verifyNodeListscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().(nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(nodes)); |
| 343 | |
| 344 | // get the first path and insert our nodes before it, if it doesn't exist then it |
| 345 | // doesn't matter, our nodes will be inserted anyway |
| 346 | const path = NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#.getscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().({ |
| 347 | parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:parentPath.: this, |
| 348 | parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:parent.: this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 349 | containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:container.: this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.[listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(listKey)] as unknown as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#[], |
| 350 | listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:listKey., |
| 351 | keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:key.: 0, |
| 352 | }).setContextscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/setContext().(this.contextscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#context.); |
| 353 | |
| 354 | return path._containerInsertBeforescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_containerInsertBefore().( |
| 355 | // @ts-expect-error typings needed to narrow down nodes as t.Node[] |
| 356 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/unshiftContainer().(nodes), |
| 357 | ); |
| 358 | } |
| 359 | |
| 360 | export function pushContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[N] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#, Kscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[K] extends keyof Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[N] & string>( |
| 361 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[N]>, |
| 362 | listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().(listKey): Kscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[K], |
| 363 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().(nodes): Nscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[N][Kscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().[K]] extends (infer E)[] |
| 364 | ? E | E[] |
| 365 | : // todo: refine to t.Node[] |
| 366 | // ? E extends t.Node |
| 367 | // ? E | E[] |
| 368 | // : never |
| 369 | never, |
| 370 | ) { |
| 371 | this._assertUnremovedscip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/_assertUnremoved().(); |
| 372 | |
| 373 | const verifiedNodes = this._verifyNodeListscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/_verifyNodeList().( |
| 374 | // @ts-expect-error refine typings |
| 375 | nodesscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().(nodes), |
| 376 | ); |
| 377 | |
| 378 | // get an invisible path that represents the last node + 1 and replace it with our |
| 379 | // nodes, effectively inlining it |
| 380 | |
| 381 | const container = this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.[listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().(listKey)]; |
| 382 | const path = NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#.getscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().({ |
| 383 | parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:parentPath.: this, |
| 384 | parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:parent.: this.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., |
| 385 | containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:container.: container as unknown as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#[], |
| 386 | listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:listKey., |
| 387 | // @ts-expect-error TS cannot infer that container is t.Node[] |
| 388 | keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#get().(`{ hub, parentPath, parent, container, listKey, key, }`)typeLiteral9:key.: container.length, |
| 389 | }).setContextscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/setContext().(this.contextscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#context.); |
| 390 | |
| 391 | return path.replaceWithMultiplescip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWithMultiple().(verifiedNodes); |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Hoist the current node to the highest scope possible and return a UID |
| 396 | * referencing it. |
| 397 | */ |
| 398 | export function hoistscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().<Tscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().[T] extends tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Nodescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Node#>( |
| 399 | thisscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().(this): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Tscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().[T]>, |
| 400 | scopescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().(scope): Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope# = this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope., |
| 401 | ) { |
| 402 | const hoister = new PathHoisterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#`<constructor>`().<Tscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().[T]>(this, scopescip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/hoist().(scope)); |
| 403 | return hoister.runscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#run().(); |
| 404 | } |