Debian Codegraph @

packages/babel-traverse/src/path/lib/hoister.ts

raw symbols SCIP
1 import { reactscip-typescript npm @babel/types 7.20.7 src/`index.ts`/react. } from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/;
2 import {
3 cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode().,
4 jsxExpressionContainerscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/jsxExpressionContainer().,
5 variableDeclarationscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/variableDeclaration().,
6 variableDeclaratorscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/variableDeclarator().,
7 } from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/;
8 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`/;
9 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`/;
10 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`/;
11 import type Bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding# from "../../scope/binding"scip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/;
12 import type { Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor# } from "../../types"scip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/;
13
14 const referenceVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/referenceVisitor.: Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor#<PathHoisterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#> = {
15 // This visitor looks for bindings to establish a topmost scope for hoisting.
16 ReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types.ts`/VirtualTypeAliases#ReferencedIdentifier.(path, state) {
17 // Don't hoist regular JSX identifiers ('div', 'span', etc).
18 // We do have to consider member expressions for hoisting (e.g. `this.component`)
19 if (
20 path.isJSXIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXIdentifier().() &&
21 reactscip-typescript npm @babel/types 7.20.7 src/`index.ts`/react..isCompatTagscip-typescript npm @babel/types 7.20.7 src/`index.ts`/isCompatTag0:(path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXIdentifier#name.) &&
22 !path.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isJSXMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXMemberExpression().()
23 ) {
24 return;
25 }
26
27 // If the identifier refers to `this`, we need to break on the closest non-arrow scope.
28 if (path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name. === "this") {
29 let scope = path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope.;
30 do {
31 if (
32 scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().() &&
33 !scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isArrowFunctionExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isArrowFunctionExpression().()
34 ) {
35 break;
36 }
37 } while ((scope = scope.parentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#`<get>parent`().));
38 if (scope) state.breakOnScopePathsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#breakOnScopePaths..pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path.);
39 }
40
41 // direct references that we need to track to hoist this to the highest scope we can
42 const binding = path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.);
43 if (!binding) return;
44
45 // we can handle reassignments only if they happen in the same scope as the declaration
46 for (const violation of binding.constantViolationsscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constantViolations.) {
47 if (violation.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope. !== binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path..scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope.) {
48 state.mutableBindingscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#mutableBinding. = true;
49 path.stopscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/stop().();
50 return;
51 }
52 }
53
54 // this binding isn't accessible from the parent scope so we can safely ignore it
55 // eg. it's in a closure etc
56 if (binding !== state.scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.)) return;
57
58 state.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.[path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.] = binding;
59 },
60 };
61
62 export default class PathHoisterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#<Tscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#[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# = 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#> {
63 breakOnScopePathsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#breakOnScopePaths.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[];
64 bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.: { [k: string]: Bindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding# };
65 mutableBindingscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#mutableBinding.: boolean;
66 private scopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scopes.: Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#[];
67 scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scope.: Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#;
68 private pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path.: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Tscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#[T]>;
69 private attachAfterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#attachAfter.: boolean;
70
71 constructorscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#`<constructor>`().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#`<constructor>`().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Tscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#[T]>, scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#`<constructor>`().(scope): Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#) {
72 // Storage for scopes we can't hoist above.
73 this.breakOnScopePathsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#breakOnScopePaths. = [];
74 // Storage for bindings that may affect what path we can hoist to.
75 this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings. = {};
76 // "true" if the current path contains a reference to a binding whose
77 // value can change and thus can't be safely hoisted.
78 this.mutableBindingscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#mutableBinding. = false;
79 // Storage for eligible scopes.
80 this.scopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scopes. = [];
81 // Our original scope and path.
82 this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scope. = scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#`<constructor>`().(scope);
83 this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path. = pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#`<constructor>`().(path);
84 // By default, we attach as far up as we can; but if we're trying
85 // to avoid referencing a binding, we may have to go after.
86 this.attachAfterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#attachAfter. = false;
87 }
88
89 // A scope is compatible if all required bindings are reachable.
90 isCompatibleScopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#isCompatibleScope().(scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#isCompatibleScope().(scope): Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#) {
91 for (const key of 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().(this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.)) {
92 const binding = this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.[key];
93 if (!scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#isCompatibleScope().(scope).bindingIdentifierEqualsscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#bindingIdentifierEquals().(key, binding.identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier.)) {
94 return false;
95 }
96 }
97
98 return true;
99 }
100
101 // Look through all scopes and push compatible ones.
102 getCompatibleScopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getCompatibleScopes().() {
103 let scope = this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope.;
104 do {
105 if (this.isCompatibleScopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#isCompatibleScope().(scope)) {
106 this.scopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scopes..pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(scope);
107 } else {
108 break;
109 }
110
111 // deopt: These scopes are set in the visitor on const violations
112 if (this.breakOnScopePathsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#breakOnScopePaths..indexOfscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#indexOf().(scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path.) >= 0) {
113 break;
114 }
115 } while ((scope = scope.parentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#`<get>parent`().));
116 }
117
118 getAttachmentPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentPath().() {
119 let path = this._getAttachmentPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#_getAttachmentPath().();
120 if (!path) return;
121
122 let targetScope = path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope.;
123
124 // don't allow paths that have their own lexical environments to pollute
125 if (targetScope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path. === path) {
126 targetScope = path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..parentscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#`<get>parent`().;
127 }
128
129 // avoid hoisting to a scope that contains bindings that are executed after our attachment path
130 if (targetScope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().() || targetScope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().()) {
131 for (const name of 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().(this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.)) {
132 // check binding is a direct child of this paths scope
133 if (!targetScope.hasOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#hasOwnBinding().(name)) continue;
134
135 const binding = this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.[name];
136
137 // allow parameter references and expressions in params (like destructuring rest)
138 if (binding.kindscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#kind. === "param" || binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path..parentKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#`<get>parentKey`(). === "params") {
139 continue;
140 }
141
142 // For each binding, get its attachment parent. This gives us an idea of where we might
143 // introduce conflicts.
144 const bindingParentPath = this.getAttachmentParentForPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path.);
145
146 // If the binding's attachment appears at or after our attachment point, then we move after it.
147 if (bindingParentPath.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. >= path.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key.) {
148 this.attachAfterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#attachAfter. = true;
149 path = binding.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#path.;
150
151 // We also move past any constant violations.
152 for (const violationPath of binding.constantViolationsscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constantViolations.) {
153 if (this.getAttachmentParentForPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(violationPath).keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key. > path.keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key.) {
154 path = violationPath;
155 }
156 }
157 }
158 }
159 }
160
161 return path;
162 }
163
164 _getAttachmentPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#_getAttachmentPath().() {
165 const scopes = this.scopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scopes.;
166
167 const scope = scopes.popscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#pop().();
168 // deopt: no compatible scopes
169 if (!scope) return;
170
171 if (scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isFunctionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunction().()) {
172 if (this.hasOwnParamBindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#hasOwnParamBindings().(scope)) {
173 // deopt: should ignore this scope since it's ourselves
174 if (this.scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scope. === scope) return;
175
176 // needs to be attached to the body
177 const bodies = scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..get("body").get("body") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#[];
178 for (let i = 0; i < bodies.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.; i++) {
179 // Don't attach to something that's going to get hoisted,
180 // like a default parameter
181 // @ts-expect-error todo(flow->ts): avoid mutating the node, introducing new fields
182 if (bodies[i].nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.._blockHoist) continue;
183 return bodies[i];
184 }
185 // deopt: If here, no attachment path found
186 } else {
187 // doesn't need to be be attached to this scope
188 return this.getNextScopeAttachmentParentscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getNextScopeAttachmentParent().();
189 }
190 } else if (scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().()) {
191 return this.getNextScopeAttachmentParentscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getNextScopeAttachmentParent().();
192 }
193 }
194
195 getNextScopeAttachmentParentscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getNextScopeAttachmentParent().() {
196 const scope = this.scopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#scopes..popscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#pop().();
197 if (scope) return this.getAttachmentParentForPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(scope.pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path.);
198 }
199
200 // Find an attachment for this path.
201 getAttachmentParentForPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) {
202 do {
203 if (
204 // Beginning of the scope
205 !pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath. ||
206 // Has siblings and is a statement
207 (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().(pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path).containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container.) && pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path).isStatementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isStatement().())
208 ) {
209 return pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path);
210 }
211 } while ((pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path) = pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentParentForPath().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.));
212 }
213
214 // Returns true if a scope has param bindings.
215 hasOwnParamBindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#hasOwnParamBindings().(scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#hasOwnParamBindings().(scope): Scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#) {
216 for (const name of 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().(this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.)) {
217 if (!scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#hasOwnParamBindings().(scope).hasOwnBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#hasOwnBinding().(name)) continue;
218
219 const binding = this.bindingsscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#bindings.[name];
220 // Ensure constant; without it we could place behind a reassignment
221 if (binding.kindscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#kind. === "param" && binding.constantscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#constant.) return true;
222 }
223 return false;
224 }
225
226 runscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#run().() {
227 this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..traversescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#traverse().(referenceVisitorscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/referenceVisitor., this);
228
229 if (this.mutableBindingscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#mutableBinding.) return;
230
231 this.getCompatibleScopesscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getCompatibleScopes().();
232
233 const attachTo = this.getAttachmentPathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#getAttachmentPath().();
234 if (!attachTo) return;
235
236 // don't bother hoisting to the same function as this will cause multiple branches to be
237 // evaluated more than once leading to a bad optimisation
238 if (attachTo.getFunctionParentscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/getFunctionParent().() === this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..getFunctionParentscip-typescript npm @babel/traverse 7.20.13 src/path/`ancestry.ts`/getFunctionParent().()) return;
239
240 // generate declaration and insert it to our point
241 let uid: 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# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.JSXExpressionContainerscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXExpressionContainer# =
242 attachTo.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..generateUidIdentifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#generateUidIdentifier().("ref");
243
244 // @ts-expect-error todo(flow->ts): more specific type for this.path
245 const declarator = variableDeclaratorscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/variableDeclarator().(uid, this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.);
246
247 const insertFn = this.attachAfterscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#attachAfter. ? "insertAfter" : "insertBefore";
248 const [attached] = attachTo[insertFn]([
249 attachTo.isVariableDeclaratorscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isVariableDeclarator().()
250 ? declarator
251 : variableDeclarationscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/variableDeclaration().("var", [declarator]),
252 ]);
253
254 const parent = this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.;
255 if (parent.isJSXElementscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isJSXElement().() && this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..containerscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#container. === parent.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..childrenscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/JSXElement#children.) {
256 // turning the `span` in `<div><span /></div>` to an expression so we need to wrap it with
257 // an expression container
258 uid = jsxExpressionContainerscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/jsxExpressionContainer().(uid);
259 }
260
261 this.pathscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`hoister.ts`/PathHoister#path..replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode().(uid));
262
263 return attachTo.isVariableDeclaratorscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isVariableDeclarator().()
264 ? attached.get("init")
265 : attached.get("declarations.0.init");
266 }
267 }