mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import { resolveVariable } from "./scope.ts";
|
|
|
|
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
|
|
function isGlobalReflect(sourceCode: SourceCode, expression: ESTree.Expression): boolean {
|
|
if (expression.type !== "Identifier" || expression.name !== "Reflect") return false;
|
|
if (sourceCode.isGlobalReference(expression)) return true;
|
|
const variable = resolveVariable(sourceCode, expression);
|
|
return variable === null || variable.defs.length === 0;
|
|
}
|
|
|
|
/** Reports whether a call target names one method on the global Reflect object. */
|
|
export function isGlobalReflectMethodCall(
|
|
sourceCode: SourceCode,
|
|
callee: ESTree.Expression,
|
|
methodName: string,
|
|
): boolean {
|
|
if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
|
|
if (!isGlobalReflect(sourceCode, callee.object)) return false;
|
|
const property = callee.property;
|
|
return callee.computed
|
|
? property.type === "Literal" && property.value === methodName
|
|
: property.type === "Identifier" && property.name === methodName;
|
|
}
|