/** * @fileoverview Shared AST utilities for fitness checks. * * Common TypeScript AST operations for tree walking and node inspection. * Used by AST-based fitness checks. Lives in @opensip-cli/lang-typescript * so the dependency on `typescript` is isolated to the language pack. * * Source parsing lives in `./parse.ts` (TSX-aware). Function-scope helpers * (findEnclosingFunction, isInAsyncContext, etc.) live in `./function-scope.ts` * and are re-exported through the package barrel; do NOT add new * function-scope helpers to this file. */ import * as ts from 'typescript'; /** * Cached parse — uses the language-aware parse cache via the registered * TS adapter. Falls back to a direct parse when no cache is active. */ export declare function getSharedSourceFile(filePath: string, content: string): ts.SourceFile | null; /** * Depth-first walk of every descendant of `root` (the root itself is * not visited — pass a SourceFile to walk an entire file, or any * non-SourceFile node to walk a subtree). If you need the root in the * visit callback, wrap with: `visitor(root); walkNodes(root, visitor)`. */ export declare function walkNodes(root: ts.Node, visitor: (node: ts.Node) => void): void; /** * Get the leaf identifier text from an expression node. */ export declare function getIdentifierName(node: ts.Node): string; /** * Get the full dotted path of a property access chain. */ export declare function getPropertyChain(node: ts.Node): string; /** * Get the 1-indexed line number for a node. */ export declare function getLineNumber(node: ts.Node, sourceFile: ts.SourceFile): number; /** * Get the column number (0-indexed) for a node. */ export declare function getColumn(node: ts.Node, sourceFile: ts.SourceFile): number; /** * Check if a node is a property access matching a specific property name. */ export declare function isPropertyAccess(node: ts.Node, propertyName: string): boolean; /** * Check if a node is a literal value. */ export declare function isLiteral(node: ts.Node): boolean; /** * Check if a node is inside a string literal or template *literal* span. * Code inside `${…}` interpolations is not treated as "in a string". */ export declare function isInStringLiteral(node: ts.Node): boolean; /** * Strip the non-semantic expression wrappers TypeScript's compiler API keeps * as distinct nodes — parentheses, `as`/angle-bracket type assertions, * `satisfies`, and non-null (`!`) — down to the innermost expression. * * Use before a shape check (`ts.isObjectLiteralExpression`, `ts.isCallExpression`, * `ts.isStringLiteral`, etc.) that should see through `(x)`, `x as T`, `x`, * `x satisfies T`, and `x!` to the expression they wrap. */ export declare function unwrapExpression(expression: ts.Expression): ts.Expression; /** * Find all call expressions matching `object.method()` pattern. */ export declare function findCallExpressions(root: ts.Node, objectName: string, methodName: string): ts.CallExpression[]; /** * Find all binary expressions with a specific operator. */ export declare function findBinaryExpressions(root: ts.Node, operator: ts.SyntaxKind): ts.BinaryExpression[]; /** * Find all template literal expressions (with substitutions). */ export declare function findTemplateLiterals(root: ts.Node): ts.TemplateExpression[]; /** * Check if a position in the source falls inside a comment. * * Walks every AST node's leading/trailing comment ranges (not only line * starts). Line-start probing misses mid-line trailing comments * (`code; // here`) and can miss interior positions of multi-line blocks * when the line start is not a token boundary TypeScript associates with * the comment. */ export declare function isInComment(position: number, sourceFile: ts.SourceFile): boolean; /** * Count unescaped backtick characters in a line. * A backtick is escaped only when preceded by an odd number of backslashes * (`\\`` is unescaped; `\`` is escaped). */ export declare function countUnescapedBackticks(line: string): number; /** Re-export TypeScript namespace for check authors */ export { ts }; //# sourceMappingURL=ast-utilities.d.ts.map