Variable initializer or function parameter that `name` refers to at `from`.
(name: string, from: ts.Node)
| 151 | |
| 152 | /** Variable initializer or function parameter that `name` refers to at `from`. */ |
| 153 | function 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 |