/** * @fileoverview Function-scope AST helpers. * * Walking helpers that answer "what function am I inside?" / "is this in an * async context?" / "is this in a conditional branch?" — used by checks that * need to reason about scope boundaries (lifecycle cleanup, async waterfall * detection, etc.). * * Lives in its own module so consumers reading these helpers don't scroll * past unrelated parsing / inspection / comment-detection code, and so the * next round of scope helpers has a sensible home rather than landing in * the general-purpose `ast-utilities.ts` module. */ import * as ts from 'typescript'; /** * Function-like nodes the helpers below treat as a "function boundary": * regular declarations, methods, function expressions, arrow functions, and * constructor declarations. The helpers stop their upward walk at any of * these. */ export type FunctionLikeNode = ts.FunctionDeclaration | ts.MethodDeclaration | ts.FunctionExpression | ts.ArrowFunction | ts.ConstructorDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration; /** * Walk up the AST from a node and return the nearest enclosing function-like * declaration. Includes constructors. Returns null when the node sits at * module scope. */ export declare function findEnclosingFunction(node: ts.Node): FunctionLikeNode | null; /** * Walk up the AST from a node and return the BODY of the nearest enclosing * function-like declaration when that body is a {@link ts.Block}. Returns * null when there is no enclosing function, or when the function uses an * expression body (e.g. an arrow function `() => x`) rather than a block. */ export declare function findEnclosingFunctionBody(node: ts.Node): ts.Block | null; /** * Return the textual name of the nearest enclosing named function-like, or * null when the enclosing function is anonymous or there is no enclosing * function. Walks past anonymous arrow functions to the next named ancestor — * e.g. for a node inside `class Foo { bar() { (() => baz())() } }`, this * returns `'bar'`, not `null`. */ export declare function getEnclosingFunctionName(node: ts.Node, sourceFile: ts.SourceFile): string | null; /** * Walk up the AST from a node and return the nearest function-like ancestor * OR the enclosing SourceFile. Differs from {@link findEnclosingFunction} in * that it always returns a node (never null) — the SourceFile acts as the * top-level scope. */ export declare function findEnclosingScope(node: ts.Node): ts.Node; /** * Return true when `node` carries the `async` modifier. Uses the modern * `canHaveModifiers` + `getModifiers` API so it is safe to call on any node * kind, not just function-likes. */ export declare function isAsync(node: ts.Node): boolean; /** * Return true when `node` is nested inside an `async` function-like ancestor. * Walks up until the first function-like is found (returns false if none), * then asks {@link isAsync} of that function. Module-top-level code returns * false — there is no enclosing async context. */ export declare function isInAsyncContext(node: ts.Node): boolean; /** * Return true when `node` is nested inside a conditional construct — `if`, * `else`, `switch` case, or a ternary expression — within its enclosing * function. Stops at function boundaries (does NOT cross into outer * functions). */ export declare function isInsideConditionalBlock(node: ts.Node): boolean; //# sourceMappingURL=function-scope.d.ts.map