sicua
Version:
A tool for analyzing project structure and dependencies
117 lines (116 loc) • 3.36 kB
TypeScript
import ts from "typescript";
/**
* Configuration options for body parsing
*/
interface BodyParsingOptions {
normalizeWhitespace: boolean;
removeComments: boolean;
maxLength: number | null;
includeLocation: boolean;
}
/**
* Parsed function body information
*/
interface ParsedFunctionBody {
body: string;
isEmpty: boolean;
isExpression: boolean;
hasReturnStatements: boolean;
lineCount: number;
characterCount: number;
location?: {
start: number;
end: number;
line: number;
column: number;
};
}
/**
* Utility class for parsing and normalizing function bodies
*/
export declare class FunctionBodyParser {
private defaultOptions;
/**
* Extracts function body as a string (for backward compatibility)
* @param node The function-like declaration
* @param options Optional parsing configuration
* @returns Cleaned function body string
*/
extractBody(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction, options?: Partial<BodyParsingOptions>): string;
/**
* Extracts detailed function body information
* @param node The function-like declaration
* @param options Optional parsing configuration
* @returns Detailed function body information
*/
extractBodyDetailed(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction, options?: Partial<BodyParsingOptions>): ParsedFunctionBody;
/**
* Checks if a function has an empty body
*/
isEmpty(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction): boolean;
/**
* Checks if function body is just an expression (arrow function)
*/
isExpressionBody(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction): boolean;
/**
* Counts return statements in a function body
*/
countReturnStatements(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction): number;
/**
* Gets the complexity score of a function body
*/
getBodyComplexity(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction): number;
/**
* Parses expression body (arrow function without braces)
*/
private parseExpressionBody;
/**
* Parses block body (function with braces)
*/
private parseBlockBody;
/**
* Parses generic body types
*/
private parseGenericBody;
/**
* Processes raw body text according to options
*/
private processBodyText;
/**
* Normalizes whitespace in code while preserving indentation
*/
private normalizeWhitespace;
/**
* Removes comments from code (basic implementation)
*/
private removeComments;
/**
* Counts lines in text
*/
private countLines;
/**
* Gets location information for a node
*/
private getLocation;
/**
* Counts return statements in a block
*/
private countReturnsInBlock;
/**
* Gets complexity score for an expression
*/
private getExpressionComplexity;
/**
* Gets complexity score for a block
*/
private getBlockComplexity;
/**
* Creates empty body result
*/
private createEmptyBody;
/**
* Creates error fallback body result
*/
private createErrorBody;
}
export {};