@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
85 lines • 3.39 kB
text/typescript
/**
* Utility function for parsing function arguments and handling nested structures
* in JavaScript/TypeScript code with structured representations.
*/
/**
* Structured argument types for discriminating between different code constructs:
* - `[Array]`: Literal array - e.g., `['1', '2', '3']`
* - `[String, Array]`: Function call - e.g., `['func', ['a', 'b']]`
* - `[String, Array, Array]`: Function with generics - e.g., `['Component', [{ foo: 'string' }], []]`
* - `[String, Array, null]`: Type with generics - e.g., `['Theme', ['"dark" | "light"'], null]`
* - `[Array, any]`: Simple arrow function - e.g., `[['evt'], 'evt.preventDefault()']`
* - `[Array, [any, any], any]`: Typed arrow function - e.g., `[['data'], ['string', 'Promise<string>'], ['Promise.resolve', ['data']]]`
* - `['as', string, any]`: TypeScript type assertion - e.g., `['as', 'React.FC<Props>', 'Component']`
* - `Record<string, any>`: Object literal - e.g., `{ key: 'value' }`
* - `string`: Plain string value
*/
export type SplitArguments = Array<string | SplitArguments | Record<string, any>>;
/**
* Type guard and extractor for literal arrays
* @param value - The value to check
* @returns Object with items array if it's a literal array, false otherwise
*/
export declare function isArray(value: any): {
items: any[];
} | false;
/**
* Type guard and extractor for function calls
* @param value - The value to check
* @returns Object with name and arguments if it's a function call, false otherwise
*/
export declare function isFunction(value: any): {
name: string;
arguments: any[];
} | false;
/**
* Type guard and extractor for generics (both function and type generics)
* @param value - The value to check
* @returns Object with name, generics, and arguments (or null for types) if it's a generic, false otherwise
*/
export declare function isGeneric(value: any): {
name: string;
generics: any[];
arguments: any[] | null;
} | false;
/**
* Type guard and extractor for arrow functions
* @param value - The value to check
* @returns Object with args, types (if typed), and returnValue if it's an arrow function, false otherwise
*/
export declare function isArrowFunction(value: any): {
args: any[];
types?: [any, any];
returnValue: any;
} | false;
/**
* Type guard and extractor for object literals
* @param value - The value to check
* @returns Object with properties if it's an object literal, false otherwise
*/
export declare function isObjectLiteral(value: any): {
properties: Record<string, any>;
} | false;
/**
* Type guard and extractor for TypeScript type assertions
* @param value - The value to check
* @returns Object with type and expression if it's a type assertion, false otherwise
*/
export declare function isTypeAssertion(value: any): {
type: string;
expression: any;
} | false;
/**
* Main API: Parse arguments and return structured representation
* This is the primary parsing function optimized for recursive data structures
*/
export declare function parseFunctionArguments(str: string): SplitArguments;
/**
* Parse entire file and extract all exports with their function calls
* Returns a mapping of export names to their function call information
*/
export declare function parseFileExports(fileContent: string): Record<string, {
functionName: string;
arguments: SplitArguments;
sourceRange: [number, number];
}>;