UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

155 lines (154 loc) 5.41 kB
/** * Utility functions for analyzing JSX structure from ComponentRelation data * Enhanced with better text extraction and accessibility analysis helpers * Updated to work with enhanced ScanResult and ProcessedContent */ import { JSXElementInfo, JSXPropValue } from "../types/accessibilityTypes"; import { ComponentRelation, ScanResult } from "../../../types"; export declare class JSXAnalysisUtils { /** * Extracts JSX elements from component content for accessibility analysis * Updated to work with enhanced ScanResult and ProcessedContent */ static extractJSXElements(component: ComponentRelation, scanResult: ScanResult): JSXElementInfo[]; /** * Gets enhanced content from ScanResult fileContents map */ private static getEnhancedContent; /** * Converts existing JSXStructure to JSXElementInfo format */ private static convertJSXStructureToElementInfo; /** * Parses JSX elements directly from component content string * Enhanced to handle TypeScript and modern JSX patterns */ private static parseJSXFromContent; /** * Converts TypeScript JSX node to JSXElementInfo * Enhanced with better error handling and context extraction */ private static convertTSNodeToElementInfo; /** * Extracts tag name from JSX node * Fixed to handle TypeScript type narrowing properly */ private static getJSXTagName; /** * Extracts props from JSX node * Enhanced with better prop value extraction */ private static extractPropsFromNode; /** * Safely extracts attribute name from different JSX attribute name types */ private static getAttributeName; /** * Extracts value from JSX attribute * Enhanced with better expression handling */ private static extractPropValue; /** * Extracts text content from JSX children * Enhanced to handle more text patterns */ private static extractTextFromJSXChildren; /** * Gets surrounding context for better error reporting * Enhanced with better context boundaries */ private static getNodeContext; /** * Extracts text content from child elements */ private static extractTextContent; /** * Infers prop type from string representation */ private static inferPropType; /** * Parses prop value from string representation */ private static parsePropValue; /** * Removes duplicate elements based on tag name, props, and content * Enhanced deduplication logic */ private static deduplicateElements; /** * Checks if an element has a specific prop */ static hasProp(element: JSXElementInfo, propName: string): boolean; /** * Gets prop value safely */ static getPropValue(element: JSXElementInfo, propName: string): JSXPropValue | undefined; /** * Checks if element has any of the specified props */ static hasAnyProp(element: JSXElementInfo, propNames: string[]): boolean; /** * Gets string value of a prop, handling different value types */ static getPropStringValue(element: JSXElementInfo, propName: string): string | undefined; /** * Checks if element is an HTML element using the comprehensive HTML_TAGS constant */ static isHTMLElement(element: JSXElementInfo): boolean; /** * Checks if element is a React component (capitalized tag name) */ static isReactComponent(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element is hidden via CSS classes */ static isHiddenByClass(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element is screen reader only */ static isScreenReaderOnly(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element is hidden via inline styles */ static isHiddenByStyle(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element is completely hidden */ static isHiddenElement(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element is likely an icon component */ static isIconComponent(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element is decorative */ static isDecorativeElement(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if variable name suggests text content */ static isTextVariable(variableName: string): boolean; /** * Enhanced helper: Checks if element has labeling props */ static hasLabelingProps(element: JSXElementInfo): boolean; /** * Enhanced helper: Checks if element has spread props */ static hasSpreadProps(element: JSXElementInfo): boolean; /** * Enhanced helper: Extracts variable names from expression */ static extractVariableNames(expression: string): string[]; /** * Enhanced helper: Checks if a string is a JavaScript keyword */ private static isJavaScriptKeyword; /** * Enhanced helper: Checks if expression likely contains text */ static expressionLikelyContainsText(expression: string): boolean; /** * Enhanced helper: Gets all accessible text sources from element */ static getAccessibleTextSources(element: JSXElementInfo): string[]; }