/** * ScopeGraph * * Thin wrapper over CodeGraph that enriches each DFGDef with declaration-keyword * awareness. Needed by the three Group-3 passes (variable-shadowing, leaked-global, * unused-variable) which must distinguish between a "real" variable declaration * (`let x = 5`) and a bare reassignment (`x = 5`). * * The DFG extractor treats both as `kind='local'` because reassignments also * create new reaching definitions. ScopeGraph recovers the distinction by * scanning the source line for language-specific declaration keywords. * * Design: * - Built once per pass via `new ScopeGraph(graph, code, language)` * - O(n) construction where n = number of DFG defs * - No mutations — all state is computed in the constructor * - Browser + Node.js safe (no platform APIs) */ import type { DFGDef } from '../types/index.js'; import type { CodeGraph } from './code-graph.js'; /** Enriched view of a single DFGDef with scope metadata. */ export interface ScopeEntry { /** The underlying DFG definition. */ readonly def: DFGDef; /** * True when the source line that created this def contains a declaration * keyword appropriate for the language (e.g. `let`/`const`/`var` for JS, * type keyword for Java, `let` for Rust). False for bare reassignments. */ readonly hasDeclKeyword: boolean; /** * `start_line` of the enclosing method, or -1 if the def is at the * top/module level (no enclosing method found). */ readonly methodStart: number; /** * `end_line` of the enclosing method, or -1 if top-level. */ readonly methodEnd: number; } export declare class ScopeGraph { /** One entry per DFGDef in the IR, in original order. */ readonly entries: ScopeEntry[]; constructor(graph: CodeGraph, code: string, language: string); /** * Returns all entries whose def falls within the inclusive range * [start, end] (both are 1-based source line numbers). */ defsInMethod(start: number, end: number): ScopeEntry[]; /** * Returns true if the given variable has at least one def with * `hasDeclKeyword === true` inside the method whose start line is * `methodStart` OR at module level (methodStart === -1). * * Module-level declarations are included because JavaScript/TypeScript * module-level `let`/`const`/`var` variables are legitimately reassigned * inside functions — that is not a global leak. * * Used by `leaked-global` to determine whether a bare assignment is truly * undeclared within its enclosing function. */ hasDeclaredDef(variable: string, methodStart: number): boolean; } //# sourceMappingURL=scope-graph.d.ts.map