css_class_extractor.ts view source
AcornPlugin Acorn plugin type - a function that extends the Parser class.
AST-based CSS class extraction for Svelte and TypeScript files.
Replaces regex-based extraction with proper parsing to handle:
- class="display:flex" - string attributes
- class={{ active, disabled: !enabled }} - object attributes (Svelte 5.16+)
- class={[cond && 'box', 'display:flex']} - array attributes (Svelte 5.16+)
- class:active={cond} - class directives
- clsx('foo', { bar: true }) - class utility function calls
- Variables with class-related names
- // @fuz-classes class1 class2 - comment hints for dynamic classes
- // @fuz-elements element1 element2 - comment hints for dynamic elements
- // @fuz-variables var1 var2 - comment hints for dynamic CSS variables
10 declarations
css_class_extractor.ts view source
AcornPlugin Acorn plugin type - a function that extends the Parser class.
css_class_extractor.ts view source
(source: string, options?: ExtractCssClassesOptions): Set<string> | null Unified extraction function that auto-detects file type. Returns just the class names as a Set.
sourcethe file source code
stringoptionsextraction options
{}Set<string> | null set of class names, or null if none found
css_class_extractor.ts view source
(source: string, options?: ExtractCssClassesOptions): ExtractionResult Unified extraction function that auto-detects file type. Returns full extraction result with locations and diagnostics.
sourcethe file source code
stringoptionsextraction options
{}ExtractionResult full extraction result with classes, tracked variables, and diagnostics
css_class_extractor.ts view source
(source: string, file?: string): ExtractionResult Extracts CSS classes from a Svelte file using AST parsing.
sourcethe Svelte file source code
stringfilefile path for location tracking
string'<unknown>'ExtractionResult extraction result with classes, tracked variables, elements, and diagnostics
css_class_extractor.ts view source
(source: string, file?: string, acorn_plugins?: AcornPlugin[] | undefined): ExtractionResult Extracts CSS classes from a TypeScript/JS file using AST parsing.
sourcethe TS/JS file source code
stringfilefile path for location tracking
string'<unknown>'acorn_plugins?additional acorn plugins (e.g., acorn-jsx for React)
AcornPlugin[] | undefinedExtractionResult extraction result with classes, tracked variables, elements, and diagnostics
css_class_extractor.ts view source
ExtractCssClassesOptions Options for CSS class extraction.
filenameFile path used to determine extraction method (Svelte vs TS) and for location tracking in diagnostics.
stringacorn_pluginsAdditional acorn plugins to use when parsing TS/JS files.
Useful for adding JSX support via acorn-jsx for React projects.
Array<AcornPlugin>css_class_extractor.ts view source
ExtractionData Cacheable extraction data fields shared between extraction and caching layers.
Uses null instead of empty collections to avoid allocation overhead.
classesMap from class name to locations where it was used, or null if none. Keys = unique classes, values = locations for diagnostics/IDE integration.
Map<string, Array<SourceLocation>> | nullexplicit_classesClasses explicitly annotated via @fuz-classes comments, or null if none.
These produce errors if they can't be resolved during generation.
Set<string> | nulldiagnosticsDiagnostics from the extraction phase, or null if none
Array<ExtractionDiagnostic> | nullelementsHTML elements found in the file, or null if none.
Used for including only the style.css rules needed.
Set<string> | nullexplicit_elementsElements explicitly annotated via @fuz-elements comments, or null if none.
These should produce errors if they have no matching style rules.
Set<string> | nullexplicit_variablesVariables explicitly annotated via @fuz-variables comments, or null if none.
These produce errors if they can't be resolved to theme variables.
Set<string> | nullcss_class_extractor.ts view source
ExtractionResult Extraction result with classes mapped to their source locations.
Extends ExtractionData with tracked_vars which is internal to AST walking.
Uses embedded diagnostics (rather than a Result type) because file extraction can partially succeed: some classes may be extracted while others produce errors. This differs from CssLiteralParseResult which uses a discriminated union because single-class parsing is binary success/failure.
tracked_varsVariables that were used in class contexts, or null if none
Set<string> | nullcss_class_extractor.ts view source
(data: ExtractionData): boolean Returns true if the extraction data has any non-null fields.
databoolean css_class_extractor.ts view source
Helper class for converting character offsets to line/column positions. Svelte template nodes (Comment, Text, ExpressionTag) only have char offsets, so this class enables efficient conversion.
Build: O(n) where n = source length Lookup: O(log m) where m = number of lines (binary search)
line_startstype Array<number>
constructortype new (source: string): SourceIndex
sourcestringget_locationConverts a character offset to a source location.
type (offset: number, file: string): SourceLocation
offset0-based character offset in the source
numberfilefile path for the location
stringSourceLocation with 1-based line and column