mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
16 lines
501 B
TypeScript
16 lines
501 B
TypeScript
import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
|
|
|
|
/** Resolve an identifier to its binding by walking lexical scopes upward. */
|
|
export function resolveVariable(
|
|
sourceCode: SourceCode,
|
|
identifier: ESTree.IdentifierReference,
|
|
): Variable | null {
|
|
let scope: Scope | null = sourceCode.getScope(identifier);
|
|
while (scope !== null) {
|
|
const variable = scope.set.get(identifier.name);
|
|
if (variable !== undefined) return variable;
|
|
scope = scope.upper;
|
|
}
|
|
return null;
|
|
}
|