Trousers

@trousers/compiler

@trousers/compiler

analyzeStyles

Source

Compile one JavaScript or TypeScript module. Returns undefined when it has no Trousers imports.

ts
function analyzeStyles(file: string, source: string, loader?: string): CompiledModule | undefined;

CompiledModule

Source

Source edits and extracted styles returned by the Rust compiler.

ts
export interface CompiledModule {
    imports: {
        start: number;
        end: number;
        replacement: string;
    }[];
    styles: {
        start: number;
        end: number;
        value: string;
        marker: string;
        rules: {
            css: string;
            retain: boolean;
            start: number;
        }[];
    }[];
}

CompileError

Source

Compiler diagnostic with the source range that triggered it.

ts
const CompileError: typeof CompileError;

sourcePositions

Source

Create a lookup from source offsets to zero-based lines and columns.

ts
function sourcePositions(source: string): (offset: number) => { line: number; character: number; };