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
8 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> Unified extraction function that auto-detects file type. Returns just the class names as a Set.
source- The file source code
stringoptions- Extraction options
{}Set<string> Set of class names
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.
source- The file source code
stringoptions- Extraction 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.
source- The Svelte file source code
stringfile- File path for location tracking
string'<unknown>'ExtractionResult Extraction result with classes, tracked variables, 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.
source- The TS/JS file source code
stringfile- File 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, 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
ExtractionResult Extraction result with classes mapped to their source locations.
Uses null instead of empty collections to avoid allocation overhead.
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 which uses a discriminated union because single-class parsing is binary success/failure.
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 should produce warnings if they can't be resolved during generation.
Set<string> | nulltracked_varsVariables that were used in class contexts, or null if none
Set<string> | nulldiagnosticsDiagnostics from the extraction phase, or null if none
Array<ExtractionDiagnostic> | nullcss_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
offset- 0-based character offset in the source
numberfile- File path for the location
stringSourceLocation with 1-based line and column