Files
element-call-Github/tools/oxlint/anti-slop/shared/scope.ts
T
2026-10-14 18:42:08 +02:00

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;
}