/**
 * Branch guards — the conditions under which a call site runs.
 *
 * An edge says `handlePress → openObjectDetail`. What a reader wants to know
 * is that it happens **when `isCollected`** and **not while `isUploading`**:
 *
 *   if (isUploading) return            ← early-return guard: !isUploading
 *   if (isCollected) {                 ← if: isCollected
 *     openObjectDetail(item)           ← the call site
 *
 * This module derives that from the AST at query time. Given a file, its
 * language and a call site (line, column), it walks from the innermost node at
 * that position up to the enclosing function boundary and records every
 * branch it passes through: `if` / `else` / `else if`, the arms of a ternary,
 * `switch` cases, the right side of `&&` / `||`, a `catch`, and — at each
 * statement block on the way — the early exits that precede the site
 * (`if (x) return`, Swift `guard x else { return }`).
 *
 * Nothing is stored in the index. The viewer and `codegraph_explore` already
 * re-read source per request (drift checks, source windows, highlighting), the
 * grammars are loaded in both processes, and a file parses in about a
 * millisecond — so labels are computed where they are shown, from the source
 * as it is now, and the index schema and the native kernel are untouched. A
 * small LRU keeps the last few parsed trees so a Symbol view that asks about
 * forty call sites in one file parses it once.
 *
 * Only what the AST states is reported. Loops are not conditions and are not
 * listed; a condition that cannot be read (a language without rules here, a
 * file that will not parse) yields no label rather than a wrong one.
 */
import type { Node as SyntaxNode } from 'web-tree-sitter';
import type { Language } from '../types';
export type GuardForm = 'if' | 'else' | 'ternary' | 'case' | 'guard' | 'and' | 'or' | 'catch';
/** How an arm leaves the flow: back to the caller, or by an error. */
export type GuardExit = 'return' | 'throw' | 'exit';
export interface BranchGuard {
    /** The condition's source, whitespace-collapsed, outer parens dropped, capped in length. */
    text: string;
    /** The site runs when the condition is FALSE (an else arm, an early-return guard, `||`). */
    negated: boolean;
    form: GuardForm;
    /** Line of the condition (1-based). */
    line: number;
    /**
     * Where the branching construct starts, `line:column` (1-based line, 0-based
     * column) — the identity of the FORK rather than of the arm: the `if` an
     * `if` guard and its `else` guard both come from, the `switch` every one of
     * its cases comes from, the `try` a `catch` belongs to. Two guards with the
     * same `branch` are arms of one decision, which is what a reader of the code
     * in its own order needs and a joined condition string cannot say.
     * '' when the walk could not place it.
     */
    branch: string;
    /** How the arm the site is IN leaves, when it always does — `return`, `throw`. */
    armExit?: GuardExit;
    /** For an early exit (`form: 'guard'`), how the arm that was NOT taken leaves. */
    exit?: GuardExit;
}
/** Languages with walk rules below. Others yield no guards (never a wrong one). */
export declare function supportsBranchGuards(language: Language | string | undefined | null): boolean;
/**
 * The label a rail or a flow connector prints: the conditions in execution
 * order, joined with `&&`, each negated one written as `!x`. Empty when the
 * site is unconditional.
 */
export declare function guardLabel(guards: readonly BranchGuard[]): string;
/**
 * Files above this size are not parsed for labels. A 300 KB source file costs
 * tens of milliseconds to parse, and a Symbol view is budgeted at 100 ms end
 * to end; a call site in such a file simply shows no `when`.
 */
export declare const MAX_PARSE_BYTES: number;
export interface CallSite {
    line: number;
    /** 0-based; null/undefined = the first non-blank column of the line. */
    column?: number | null;
    /**
     * The callee's last segment, when known (`json` for `res.status(201).json(…)`):
     * a position at the start of a chain sits on the innermost call, and the
     * climb continues to the call that is actually this one.
     */
    callee?: string;
}
export declare function siteKey(site: CallSite): string;
/**
 * Guards for many call sites in one file, keyed by {@link siteKey}. The file
 * is parsed once (and cached across requests until it changes on disk). A
 * language without rules, or a file that cannot be read or parsed, yields an
 * empty map.
 */
export declare function guardsForFile(absPath: string, language: Language, sites: readonly CallSite[]): Promise<Map<string, BranchGuard[]>>;
/**
 * Synchronous twin of {@link guardsForFile} for callers that cannot await
 * (the explore text builder). It only serves languages whose grammar is
 * ALREADY loaded — see {@link warmBranchGuardGrammars} — and yields an empty
 * map otherwise, never a wrong label.
 */
export declare function guardsForFileSync(absPath: string, language: Language, sites: readonly CallSite[]): Map<string, BranchGuard[]>;
/** The languages with rules here — what {@link warmBranchGuardGrammars} loads. */
export declare const BRANCH_GUARD_LANGUAGES: readonly Language[];
/**
 * The arguments a call site passes, as written, abbreviated to what a reader
 * scans for: a string literal whole (a storage key, a URL, a message), a name
 * whole, an object as its keys (`{ email, password }`), an array as `[…]`, a
 * function as `() => …`, a nested call as `f(…)`. The conditions say WHEN a
 * step runs; this says WITH WHAT — `SecureStore.setItemAsync('userEmail',
 * values.email)` is a different fact from `SecureStore.setItemAsync`.
 *
 * Keyed by {@link siteKey} like the guards, read from the same cached tree.
 * A site that is not inside a call, or a language without rules, is absent.
 */
export declare function callArgumentsForFile(absPath: string, language: Language, sites: readonly CallSite[]): Promise<Map<string, string>>;
/** {@link callArgumentsForFile} over source text — the test surface. */
export declare function callArgumentsInSource(source: string, language: Language, line: number, column: number | null): Promise<string | null>;
export declare function callArgumentsInTree(root: SyntaxNode, source: string, line: number, column: number | null): string | null;
/** One call site, both halves: what is called, as written, and what it is passed. */
export interface CallSiteText {
    /**
     * The callee as written, normalised: `prisma.article.findFirst`,
     * `this.owners.findById().orElseThrow`, `res.status().json` — member
     * chains kept whole (the index keeps only the last segment of a deep
     * chain), argument lists emptied, `await`/`new` dropped, `?.` as `.`.
     */
    callee: string;
    /** The argument list, abbreviated as {@link callArgumentsForFile} says. */
    args: string;
    /** The same arguments one by one — a registration site's middleware chain is `argList.slice(1, -1)`. */
    argList: string[];
    /** A status code written as an object property in the arguments (`{ status: 201 }`), which the abbreviation to keys would hide. */
    status?: number;
    /** Where the call starts and ends in the source (1-based lines) — the span another site may be written inside. */
    span?: {
        start: {
            line: number;
            column: number;
        };
        end: {
            line: number;
            column: number;
        };
    };
    /**
     * The call this one is written inside the arguments of — `res.json` for the
     * `generateToken(…)` in `res.json({ token: generateToken(…) })` — normalised
     * like `callee`. Absent at the top of a statement, and never reaching out of
     * the function or block the call is in.
     */
    within?: string;
}
export declare function callSiteInTree(root: SyntaxNode, source: string, line: number, column: number | null, want?: string): CallSiteText | null;
/** Both halves of every site, keyed by {@link siteKey}, from one cached tree. */
export declare function callSitesForFile(absPath: string, language: Language, sites: readonly CallSite[]): Promise<Map<string, CallSiteText>>;
/** {@link callSitesForFile} over source text — the test surface. */
export declare function callSiteInSource(source: string, language: Language, line: number, column: number | null): Promise<CallSiteText | null>;
/**
 * What binds a call site to an event, when something does — the answer to
 * "at what point does this run": the JSX attribute the site sits under
 * (`onPress` of `<Button>`), the `on*` option it is written in (`onSubmit`
 * of `useFormik({…})`), or the runs-later call it is an argument of
 * (`useEffect`, `setTimeout`, `addListener('x')`, `.then`).
 */
export interface SiteTrigger {
    /**
     * `prop` / `option` / `callback` are read at the site (below). `request`
     * (a route: `name` the verb, `of` the path), `decorator` (`@Process('email')`:
     * `name` the decorator, `of` its literal argument) and `load` (a page's own
     * load-time work) are set by the Steps endpoint from the registration
     * site, not read from the tree.
     */
    kind: 'prop' | 'option' | 'callback' | 'request' | 'decorator' | 'load';
    /** `onPress`, `onSubmit`, `useEffect`, `addListener`, `POST`, `Process`. */
    name: string;
    /** `Button` for a prop, `useFormik` for an option, the first string argument for a callback; null when unknown. */
    of: string | null;
    /** What runs before it fires — the middleware / guard chain at the registration site, in order. */
    after?: string[];
}
export declare function triggersForFile(absPath: string, language: Language, sites: readonly CallSite[]): Promise<Map<string, SiteTrigger>>;
/** {@link triggersForFile} over source text — the test surface. */
export declare function triggerInSource(source: string, language: Language, line: number, column: number | null): Promise<SiteTrigger | null>;
export declare function triggerInTree(root: SyntaxNode, source: string, line: number, column: number | null): SiteTrigger | null;
/** Load the grammars {@link guardsForFileSync} needs; a no-op once loaded, never throws. */
export declare function warmBranchGuardGrammars(only?: readonly Language[]): Promise<void>;
/** Guards for one site in source text — the test seam; production reads files. */
export declare function guardsInSource(source: string, language: Language, line: number, column?: number | null): Promise<BranchGuard[]>;
/** Loops for one site in source text — the test seam; production reads files. */
export declare function loopsInSource(source: string, language: Language, line: number, column?: number | null): Promise<SiteLoop[]>;
/** A loop a site is written inside: its header as written, and where the loop starts. */
export interface SiteLoop {
    /** `const item of items`, `i = 0; i < n; i++`, `queue.length > 0` — the header, without its keyword. */
    text: string;
    /** `each` for a `for` / `foreach` / `for … in`, `while` for a `while` / `do` / `repeat`. */
    kind: 'each' | 'while';
    /** Where the loop starts, `line:column` — the same identity a guard's `branch` carries. */
    branch: string;
}
/**
 * The loops a site is written inside, outermost first — what tells a reading in
 * the code's order that a run of calls happens once PER ITEM rather than once.
 * The climb is the guards' climb (the same boundaries, the same transparent
 * inline functions), so a callback's body is read in its own function and a
 * `.forEach` body under the loop it is written in.
 */
export declare function loopsInTree(root: SyntaxNode, source: string, language: Language, line: number, column: number | null): SiteLoop[];
/** Loops for many sites in one file, keyed by {@link siteKey}. */
export declare function loopsForFile(absPath: string, language: Language, sites: readonly CallSite[]): Promise<Map<string, SiteLoop[]>>;
/**
 * The walk. `line` is 1-based, `column` 0-based (null → first non-blank).
 * Returns the guards outermost first — execution order, the way a reader
 * would list them.
 */
export declare function guardsInTree(root: SyntaxNode, source: string, language: Language, line: number, column: number | null): BranchGuard[];
/**
 * The decorators / annotations / attributes on the definition at a line, and
 * on the class that holds it: `UseGuards(AuthGuard('jwt'))`,
 * `PreAuthorize("hasRole('ADMIN')")`, `HttpPost("items")`, `Process('email')`.
 * Text as written, without the `@` or the brackets, whitespace collapsed,
 * capped. The index keeps no decorators, so they are read here at request
 * time like the guards.
 */
/**
 * A `return` a definition makes itself — never one inside a lambda, a local
 * function or a nested / anonymous class — with what it returns, as written.
 * `value` is the string a same-class constant holds, when the expression is
 * a bare name that declares one: Spring MVC handlers return
 * `VIEWS_OWNER_CREATE_OR_UPDATE_FORM`, and the view is its value.
 */
export interface ReturnSite {
    line: number;
    column: number;
    expression: string;
    value?: string;
}
export declare function returnsForFile(absPath: string, language: Language, line: number): Promise<ReturnSite[]>;
/** {@link returnsForFile} over source text — the test surface. */
export declare function returnsInSource(source: string, language: Language, line: number): Promise<ReturnSite[]>;
export declare function returnsInTree(root: SyntaxNode, line: number): ReturnSite[];
export interface DefinitionDecorators {
    own: string[];
    /** The enclosing class's, when the definition is a member. */
    class: string[];
}
export declare function decoratorsForFile(absPath: string, language: Language, lines: readonly number[]): Promise<Map<number, DefinitionDecorators>>;
/** {@link decoratorsForFile} over source text — the test surface. */
export declare function decoratorsInSource(source: string, language: Language, line: number): Promise<DefinitionDecorators | null>;
export declare function decoratorsInTree(root: SyntaxNode, source: string, line: number): DefinitionDecorators | null;
/**
 * The declared types of a class's members, read from the tree: the
 * constructor's parameter properties (`private readonly usersService:
 * UsersService`), its fields (`private final OwnerRepository owners`,
 * `val owners: OwnerRepository`, `private readonly IRepo _repo`), its typed
 * properties. The index keeps no type for these, and a member call the
 * extractor kept only the last segment of (`this.usersService.findByEmail`
 * → `findByEmail`) resolves by name alone; the declared type is what says
 * where it really goes, and whether it leaves the index.
 *
 * Keyed by member name, the type as written without generics'
 * arguments (`Repository<Cat>` → `Repository<Cat>` is kept whole; callers
 * strip what they need).
 */
export declare function memberTypesForFile(absPath: string, language: Language, line: number): Promise<Map<string, string>>;
/** {@link memberTypesForFile} over source text — the test surface. */
export declare function memberTypesInSource(source: string, language: Language, line: number): Promise<Map<string, string>>;
export declare function memberTypesInTree(root: SyntaxNode, source: string, line: number): Map<string, string>;
//# sourceMappingURL=branch-guards.d.ts.map