import type { Maybe } from '@dereekb/util'; /** * The bundler hint string that marks a function call as side-effect-free. */ export declare const NO_SIDE_EFFECTS_TAG = "@__NO_SIDE_EFFECTS__"; type AstNode = any; export interface JsdocCommentInfo { readonly node: AstNode; readonly text: string; readonly hasNoSideEffects: boolean; } export interface FunctionLeadingContext { readonly jsdoc: Maybe; /** * Adjacent `@__NO_SIDE_EFFECTS__` line/block comments that should be migrated into the JSDoc * and removed. Excludes the implementation-leading annotation on overloaded functions, which * is tracked separately by {@link implLineComment} because it must be preserved. */ readonly orphanLineComments: readonly AstNode[]; /** * True when this implementation is preceded by sibling overload signatures (`TSDeclareFunction` * statements with the same name). */ readonly hasOverloads: boolean; /** * The `@__NO_SIDE_EFFECTS__` line/block comment immediately above the implementation * declaration when the function has overloads. TypeScript erases overload signatures during * emit, so JSDoc placed only on the first overload is dropped from the bundled JS — the * line comment directly above the implementation is what survives and reaches the bundler. * * `null` when the function is single-signature (the line comment is then a removable orphan) * or when no such comment is present. */ readonly implLineComment: Maybe; /** * True when the implementation will carry the `@__NO_SIDE_EFFECTS__` annotation in the emitted * JavaScript: * * - Single-signature: true when the (only) JSDoc carries the tag. * - Overloaded: true when a line/block comment with the tag sits immediately above the * implementation, OR the implementation has its own JSDoc carrying the tag. * * This is the signal upstream packages need so esbuild/rollup can tree-shake unused calls. */ readonly implHasSurvivingAnnotation: boolean; /** * The first statement in the overload chain (i.e. the first overload's export wrapper, or the * implementation itself when there are no overloads). Use this as the insertion anchor when * creating a brand-new JSDoc for the function, since docs conventionally live on the first * overload rather than the implementation. */ readonly chainStartStatement: AstNode; } /** * Returns true if the given comment text contains the @__NO_SIDE_EFFECTS__ marker. * * @param text - The comment body text (without the `/*` and `*\/` delimiters). * @returns True when the marker substring is present. */ export declare function commentContainsNoSideEffects(text: string): boolean; /** * Returns the leading whitespace (column indent) of the line containing the given offset. * * @param sourceText - The full source text being inspected. * @param offset - A character offset into `sourceText` indicating the line of interest. * @returns The whitespace prefix (spaces/tabs) of that line. */ export declare function getLineIndent(sourceText: string, offset: number): string; /** * Returns the outermost statement node for a FunctionDeclaration — its `ExportNamedDeclaration` * or `ExportDefaultDeclaration` parent if exported, otherwise the declaration itself. This is the * node ESLint attaches leading comments to. * * @param node - The FunctionDeclaration AST node. * @returns The statement node ESLint attaches leading comments to. */ export declare function getStatementAnchor(node: AstNode): AstNode; /** * Returns the JSDoc Block comment immediately preceding `anchor`, or `null` when * the anchor has no JSDoc leader. Used by the `@dbx` companion-tag rules * to locate the tagged declaration's documentation. * * @param sourceCode - The ESLint `SourceCode` object. * @param anchor - The statement-level node ESLint attaches leading comments to. * @returns The JSDoc block comment, or null when none is present. */ export declare function leadingJsdocFor(sourceCode: AstNode, anchor: AstNode): Maybe; /** * Walks backward from the implementation FunctionDeclaration through any overload signatures * with the same name, collecting:. * * - The leading JSDoc block (preferring the one attached to the **first** overload, since that's * where the function's documentation conventionally lives). * - All orphan `@__NO_SIDE_EFFECTS__` line/block comments encountered between overloads or * between the last overload and the implementation. * * This handles the common pattern: * * ```ts * \/\*\* doc \*\/ * export function foo(a: number): number; * export function foo(a: string): string; * \/\/ \@__NO_SIDE_EFFECTS__ * export function foo(a: any) { ... } * ``` * * @param sourceCode - The ESLint `SourceCode` object used to read leading comments. * @param implNode - The implementation FunctionDeclaration node. * @returns The leading JSDoc (if any) and any orphan side-effect annotation comments. */ export declare function findFunctionLeadingContext(sourceCode: AstNode, implNode: AstNode): FunctionLeadingContext; export {};