MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveBinding

Function resolveBinding

__tests__/child-process-windows-hide.test.ts:153–168  ·  view source on GitHub ↗

Variable initializer or function parameter that `name` refers to at `from`.

(name: string, from: ts.Node)

Source from the content-addressed store, hash-verified

151
152/** Variable initializer or function parameter that `name` refers to at `from`. */
153function resolveBinding(name: string, from: ts.Node): ts.VariableDeclaration | ts.ParameterDeclaration | null {
154 for (let scope: ts.Node | undefined = from.parent; scope; scope = scope.parent) {
155 if (ts.isFunctionLike(scope)) {
156 const param = scope.parameters.find((p) => ts.isIdentifier(p.name) && p.name.text === name);
157 if (param) return param;
158 }
159 if (ts.isBlock(scope) || ts.isSourceFile(scope) || ts.isModuleBlock(scope)) {
160 for (const stmt of scope.statements) {
161 if (!ts.isVariableStatement(stmt)) continue;
162 const decl = stmt.declarationList.declarations.find((d) => ts.isIdentifier(d.name) && d.name.text === name);
163 if (decl) return decl;
164 }
165 }
166 }
167 return null;
168}
169
170/**
171 * The argument every call of the function that declares `param` passes for it

Callers 1

hideStateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected